home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_04 / mc.doc < prev    next >
Text File  |  1994-03-20  |  177KB  |  3,623 lines

  1.           
  2.           
  3.           
  4.           
  5.           
  6.           
  7.           
  8.           
  9.           
  10.           ===========================================================
  11.                 DDDDD           DDDDD               SSSS
  12.                  D   Dunfield    D   D             S
  13.                  D   D           D   Development    SSSS 
  14.                  D   D           D   D                  Systems
  15.                 DDDDD           DDDDD               SSSS
  16.           ===========================================================
  17.           MM   MM  IIIIIII    CCCC   RRRRRR     OOO             CCCC
  18.           M M M M     I      C    C  R     R   O   O           C    C
  19.           M  M  M     I     C        R     R  O     O         C
  20.           M     M     I     C        RRRRRR   O     O  -----  C
  21.           M     M     I     C        R   R    O     O         C
  22.           M     M     I      C    C  R    R    O   O           C    C
  23.           M     M  IIIIIII    CCCC   R     R    OOO             CCCC
  24.           ===========================================================
  25.     
  26.     
  27.     
  28.     
  29.     
  30.                              A compact 'C' compiler
  31.                                       for
  32.                                  Small Systems.
  33.     
  34.     
  35.                                 Technical Manual
  36.     
  37.     
  38.     
  39.     
  40.     
  41.                                   Release 3.02
  42.     
  43.                                Revised 09-Feb-94
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.     
  55.     
  56.                        Copyright 1988-1994 Dave Dunfield
  57.                               All rights reserved
  58.     MICRO-C                                                          Page: 1
  59.  
  60.  
  61.     1. INTRODUCTION
  62.     
  63.           DDS MICRO-C is a compact, portable compiler for the  'C'  language
  64.        which is suitable for implementation on small 8 or  16  bit  computer
  65.        systems. It may be used as a  resident  or  cross  compiler,  and  is
  66.        capable of generating ROMable code. It is distributed in source form,
  67.        and thus provides a learning tool for those wishing  to  examine  the
  68.        internals of a working compiler.
  69.     
  70.           The main goal in the development of MICRO-C, has been to provide a
  71.        reasonably powerful language  which  will  be  portable  with  little
  72.        difficulty to many  target  systems.  The  'C'  language  was  chosen
  73.        because  it  was  designed  to  be  portable,  and   provides   ample
  74.        programming power. MICRO-C provides  an  alternative  to  interpreted
  75.        BASIC or assembly language  programming  which  are  often  the  only
  76.        languages available on small 8 bit systems.
  77.     
  78.           With today's focus on larger computers and workstations,  software
  79.        support for small  systems  and  micro-controller  sized  devices  is
  80.        getting both hard to find, and expensive.  MICRO-C  helps  fill  that
  81.        gap, because all files necessary to port and  maintain  the  compiler
  82.        are included on the distribution disks, allowing it to  be  moved  to
  83.        ANY system without dependance on a software vendor.
  84.     
  85.           Included in this package is a complete  IBM/PC  implementation  of
  86.        MICRO-C, with a comprehensive  library,  which  you  may  use  as  an
  87.        example installation. This implementation of  the  compiler  requires
  88.        the Microsoft MASM (or compatible) assembler.
  89.     
  90.           The MICRO-C "package" (software and documentation) is copyrighted,
  91.        and may  not  be  re-distributed  in  any  form  without  my  written
  92.        permission. If you have received the  "DEMO"  archive,  and  wish  to
  93.        obtain the entire MICRO-C package complete with source code, fill out
  94.        and send the order form contained in the "READ.ME" file,  along  with
  95.        the required payment to:
  96.     
  97.                            Dunfield Development Systems
  98.                            P.O. Box 31044
  99.                            Nepean, Ontario (Canada)
  100.                            K2B 8S8
  101.     
  102.           Please make your  cheque  or  money  order  payable  to  "Dunfield
  103.        Development Systems".
  104.     
  105.           MICRO-C is provided on an "as is" basis, with no warranty  of  any
  106.        kind. In no event shall the author be liable for any damages  arising
  107.        from its use or distribution.
  108.     MICRO-C                                                          Page: 2
  109.  
  110.  
  111.        1.1 Compiler Portability
  112.     
  113.              MICRO-C is written in standard 'C', and is capable of compiling
  114.           itself. This allows any system  with  a  'C'  compiler  (including
  115.           MICRO-C) to be used to port MICRO-C to another processor.
  116.     
  117.              The  parser  makes  very  few  assumptions  about  the   target
  118.           processor  or  operating  system  architecture,  allowing  a  code
  119.           generator  to  be  written  for  virtually   any   processor   and
  120.           environment.
  121.     
  122.              With the exception of required I/O routines (described  later),
  123.           the MICRO-C compiler uses no library functions, and relies  on  no
  124.           system services.
  125.     
  126.              Assuming that the code generator is fairly efficent,  and  that
  127.           the I/O routines and code generator are not unreasonably large,  a
  128.           full MICRO-C compiler may be implemented on systems with as little
  129.           as 32K of free ram and a single floppy disk.
  130.     
  131.        1.2 Code Portability
  132.     
  133.              With few exceptions, this compiler follows the  syntax  of  the
  134.           "standard" UNIX compiler (within  its  subset  of  the  language).
  135.           Programs written in MICRO-C should compile with few changes  under
  136.           other "standard" compilers.
  137.     
  138.           1.2.1 Unsupported Features:
  139.     
  140.                 MICRO-C does not currently support the following features of
  141.              standard 'C':
  142.     
  143.                     Long / Double / Float / Enumerated data types,
  144.                     Typedef and Bit fields.
  145.     
  146.           1.2.2 Additional Features
  147.     
  148.                 MICRO-C provides a few additional  features  which  are  not
  149.              always included in "standard" 'C' compilers:
  150.     
  151.                     Unsigned character variables, Nested comments, 16 bit
  152.                     character constants, Inline assembly code capability.
  153.     MICRO-C                                                          Page: 3
  154.  
  155.  
  156.        1.3 The compiling process
  157.     
  158.              There are five  programs  which  work  together  to  completely
  159.           compile a MICRO-C program:
  160.     
  161.              The PREPROCESSOR (MCP) takes  the  original  'C'  source  file,
  162.           performs MACRO expansion and incorporates the contents of  INCLUDE
  163.           files  to  get  a  "pure"  'C'  output  file.  A   less   powerful
  164.           pre-processor is also contained inside the COMPILER, which  allows
  165.           this step to  be  skipped  for  programs  which  use  only  simple
  166.           pre-processor functions.
  167.     
  168.              The COMPILER  (MCC)  reads  a  file  containing  a  'C'  source
  169.           program, and translates it into an  equivalent  assembly  language
  170.           program.
  171.     
  172.              The OPTIMIZER (MCO) reads the assembly language output from the
  173.           compiler identifying and replacing "general" code produced by  the
  174.           compiler with more efficent code which is equivalent  in  specific
  175.           cases. This step is  optional,  allowing  you  to  choose  between
  176.           faster compile time and greater program efficency.
  177.     
  178.              The ASSEMBLER takes  the  assembly  language  produced  by  the
  179.           COMPILER or OPTIMIZER, and produces an OBJECT FILE which  contains
  180.           the executable code and external reference map for the program.
  181.     
  182.              The LINKER combines the executable code from  the  OBJECT  FILE
  183.           with code from  other  programs  which  it  calls  (including  any
  184.           LIBRARY functions), to produce a complete  stand-alone  executable
  185.           program.
  186.     
  187.              The ASSEMBLER and LINKER  are  NOT  included  as  part  of  the
  188.           MICRO-C package. These programs are  specific  to  the  particular
  189.           system, and must be obtained from the system vendor.
  190.     
  191.              Some cross ASSEMBLER's do  not  produce  an  object  file,  but
  192.           generate the executable program directly  instead.  These  systems
  193.           assume that the ENTIRE program is completely contained in a SINGLE
  194.           assembly language file. This type  of  system  prevents  you  from
  195.           using a object LIBRARY which is  an  integral  feature  of  any  C
  196.           programming system.
  197.     
  198.              To  accomodate  this  type  of  development   system,   without
  199.           sacrificing the ability to use a LIBRARY,  a  program  called  the
  200.           SOURCE LINKER (SLINK)  is  included  with  MICRO-C.  This  program
  201.           combines your program  with  library  functions  at  the  ASSEMBLY
  202.           LANGUAGE level, allowing the entire program code to  be  presented
  203.           to the assembler in a single file. See the section  entitled  "THE
  204.           SOURCE LINKER" for additional information.
  205.     MICRO-C                                                          Page: 4
  206.  
  207.  
  208.     2. THE COMMAND CO-ORDINATOR
  209.     
  210.           'CC' is a utility which co-ordinates  the  execution  of  programs
  211.        required for each step of the compilation process to provide a simple
  212.        "one step" compilation  command.  This  MICRO-C  package  includes  a
  213.        version of  the  command  co-ordinator  which  handles  the  commands
  214.        necessary to compile for the 8086 processor  (MCP,  MCC,  MCO,  MASM,
  215.        LINK and EXE2BIN). This program  can  be  modified  as  necessary  to
  216.        handle other processors.
  217.     
  218.        2.1 The CC command
  219.     
  220.              The format of the 'CC' command is:
  221.     
  222.                               CC <name> [options]
  223.     
  224.           2.1.1 Command line options
  225.     
  226.                 -A      - produce ASSEMBLER (.ASM) output file
  227.                 -C      - Include 'C' source as comments in ASM files
  228.                 -F      - Fold identical string constants.
  229.                 -K      - KEEP all temporary files (do not delete)
  230.                 -L      - produce LINKABLE  (.OBJ) output file
  231.                 -O      - OPTIMIZE the output code (using MCO)
  232.                 -P      - use the extended PRE-PROCESSOR (MCP)
  233.                 -Q      - QUIET mode (suppress informational messages)
  234.                 -S      - produce SMALL-MODEL (.EXE) output file
  235.                 H=mcdir - specify MICRO-C home directory
  236.                 T=mctmp - specify prefix for TEMPORARY files
  237.     
  238.                 name=xx - Predefine macro symbol (use with -P only)
  239.     
  240.                 When executing the sub-commands, CC will search the  MICRO-C
  241.              home directory, as well as any  directories  specified  in  the
  242.              'PATH' environment variable. Libraries are  accessed  from  the
  243.              MICRO-C home directory only.
  244.     
  245.                 The environment variable 'MCDIR' is  examined  to  determine
  246.              the path to  the  MICRO-C  home  directory.  If  MCDIR  is  not
  247.              defined, CC will assume the string '\MC'. You may override this
  248.              directory by using the 'h=' option on the command line.
  249.     
  250.                 Intermediate  results  from  each  command  are  stored   in
  251.              "temporary" files, which are fed as input to the next  command.
  252.              Temporary files will be deleted once they are no longer needed,
  253.              except in the case where a command fails.  When  this  happens,
  254.              any temporary file which  was  being  used  as  input  to  that
  255.              command will not be deleted, allowing you to examine it for the
  256.              cause of the error.
  257.     MICRO-C                                                          Page: 5
  258.  
  259.  
  260.                 The environment variable 'MCTMP' is examined to determine  a
  261.              prefix to prepend to temporary file  names.  If  MCTMP  is  not
  262.              defined, CC assumes the default prefix of '$'. You may override
  263.              this prefix by using the 't=' option on the command line.
  264.     
  265.                 Here are example 'SET' commands suitable  for  inclusion  in
  266.              the AUTOEXEC.BAT file, of an IBM/PC based MICRO-C system  which
  267.              has the home directory in 'C:\MC', and a TEMP  directory  on  a
  268.              RAMDISK as drive 'D':
  269.     
  270.                     SET MCDIR=C:\MC
  271.                     SET MCTMP=D:\TEMP\      (Note trailing '\')
  272.     
  273.                 The '-A' option  causes  CC  to  bypass  the  assembler  and
  274.              linker, and produce an assembly source file (<name>.ASM) as the
  275.              output file. If the '-C' option is also used,  this  file  will
  276.              contain the 'C' source code in the form of comments. NOTE:  The
  277.              source code inserted by '-C' will  restrict  the  optimizer  to
  278.              operate only on sections of code produced by a single 'C' line.
  279.     
  280.                 The '-F' option causes the compiler to  "fold"  its  literal
  281.              pool (the area of memory where string  constants  are  stored).
  282.              This means that identical strings  not  contained  in  explicit
  283.              variables, will occur only once in memory. Since most  programs
  284.              never modify such strings, it is usually safe to do this.  Note
  285.              however that this is a violation of the 'C' standard ("The  'C'
  286.              Programming Language"  page  181  -  "All  strings,  even  when
  287.              written identically, are distinct"),  and  it  is  possible  to
  288.              write programs which will not work properly when this option is
  289.              used.
  290.     
  291.                 The '-L' option causes CC to  bypass  the  link  stage,  and
  292.              produce a linkable object module  (<name>.OBJ)  as  the  output
  293.              file.
  294.     
  295.                 The '-S' option causes CC to  link  the  program  using  the
  296.              SMALL  memory  model,   and   produce   an   executable   image
  297.              (<name>.EXE) as the output file. This option  applies  only  to
  298.              those  processors  which  have  a  segmented  architecture  and
  299.              multiple memory models such as the 8086.
  300.     
  301.                 If none of '-A', '-L' or '-S' is specified, CC will link the
  302.              program using the TINY memory  model,  and  produce  a  command
  303.              image (<name>.COM) as the output file.
  304.     
  305.                 If any of the programs  executed  by  CC  fail  to  complete
  306.              properly, CC will show the message "PGM failed (RC)", where PGM
  307.              is the name of the offending program, and RC is the DOS  return
  308.              code value. Common RC values under MSDOS are:
  309.     
  310.                 2   - Command not found (Check MCDIR and PATH setup)
  311.                 3   - Path not found    (Check MCDIR and PATH setup)
  312.                 254 - Program found errors during processing
  313.                 255 - Program was invoked with incorrect arguments
  314.     MICRO-C                                                          Page: 6
  315.  
  316.  
  317.        2.2 Using multiple object modules
  318.     
  319.              The 'LC' command takes one or more object modules  produced  by
  320.           'CC' with the '-L' option, and links them with  the  libraries  to
  321.           produce an executable module. This module will be given  the  name
  322.           of the first file specified in the argument list.
  323.     
  324.              When compiling large programs which have more than  one  source
  325.           file, you must first compile all modules using 'CC' with the  '-L'
  326.           option, and the use 'LC' to link the resultant object  files  into
  327.           the final executable program.
  328.     
  329.              The '-S' option may be used as the FIRST argument, to cause  LC
  330.           to link in the SMALL model.
  331.                 eg: CC FIRST -L
  332.                     CC SECOND -L
  333.                     LC FIRST SECOND         <-- TINY  Model
  334.                     LC -S FIRST SECOND      <-- SMALL Model
  335.     
  336.              The exact syntax  and  options  available  for  'CC'  and  'LC'
  337.           commands may differ in specific implementations of  the  compiler.
  338.           See the 'READ.ME' file and any additional technical  documentation
  339.           on your distribution disk(s) for details.
  340.     MICRO-C                                                          Page: 7
  341.  
  342.  
  343.     3. THE MICRO-C PROGRAMMING LANGUAGE
  344.     
  345.           The following pages contain a brief summary of  the  features  and
  346.        constructs implemented in MICRO-C.
  347.     
  348.           This document does not  attempt  to  teach  'C'  programming,  and
  349.        assumes that the reader is familiar with the language.
  350.     
  351.        3.1 Constants
  352.     
  353.              The following forms of constants are supported by the compiler:
  354.     
  355.                 <num>       - Decimal number        (0 - 65535)
  356.                 0<num>      - Octal number          (0 - 0177777)
  357.                 0x<num>     - Hexidecimal number    (0x0 - 0xffff)
  358.                 '<char>'    - Character             (1 or 2 chars)
  359.                 "<string>"  - Address of literal string.
  360.     
  361.              The following "special" characters may be used within character
  362.           constants or strings:
  363.     
  364.                 \n          - Newline (line-feed)   (0x0a)
  365.                 \r          - Carriage Return       (0x0d)
  366.                 \t          - Tab                   (0x09)
  367.                 \f          - Formfeed              (0x0c)
  368.                 \b          - Backspace             (0x08)
  369.                 \<num>      - Octal value <num>     (Max. three digits)
  370.                 \x<num>     - Hex value <num>       (Max. two digits)
  371.                 \<char>     - Protect character <char> from input scanner.
  372.     
  373.        3.2 Symbols
  374.     
  375.              Symbol names  may  include  the  characters  'a'-'z',  'A'-'Z',
  376.           '0'-'9', and '_'. The characters '0'-'9' may not be  used  as  the
  377.           first character in the  symbol  name.  Symbol  names  may  be  any
  378.           length, however, only the first 15 characters are significant.
  379.     
  380.              The "char" modifier may be used to declare a symbol as an 8 bit
  381.           wide value, otherwise it is assumed to be 16 bits.
  382.     
  383.                               eg: char input_char;
  384.     
  385.              The "int" modifier may be used to declare a symbol as a 16  bit
  386.           wide value. This is assumed if neither "int" or "char" is given.
  387.     
  388.                                   eg: int abc;
  389.     
  390.              The "unsigned" modifier may be used to declare a symbol  as  an
  391.           unsigned positive only value. Note that unlike some 'C' compilers,
  392.           this modifier may be applied to a character (8 bit) variable.
  393.     
  394.                             eg: unsigned char count;
  395.     MICRO-C                                                          Page: 8
  396.  
  397.  
  398.              The "extern" modifier causes the compiler to be  aware  of  the
  399.           existance and  type  of  a  global  symbol,  but  not  generate  a
  400.           definition for that symbol. This allows the module being  compiled
  401.           to reference a symbol which is defined  in  another  module.  This
  402.           modifier may not be used with local symbols.
  403.     
  404.                             eg: extern char getc();
  405.     
  406.              A  symbol  declared  as  external  may  be  re-declared  as   a
  407.           non-external at a later  point  in  the  code,  in  which  case  a
  408.           definition for it will be generated. This allows  "extern"  to  be
  409.           used to inform the compiler of a function or variable type so that
  410.           it can be referenced  properly  before  that  symbol  is  actually
  411.           defined.
  412.     
  413.              The "static" modifier causes global  symbols  to  be  available
  414.           only in the file where they are defined.  Variables  or  functions
  415.           declared  as  "static"  will  not  be   accessable   as   "extern"
  416.           declarations in other object files, nor will they cause  conflicts
  417.           with duplicate names in those files.
  418.     
  419.                          eg: static int variable_name;
  420.     
  421.              When applied to local symbols,  the  "static"  modifier  causes
  422.           those variables to be allocated in  a  reserved  area  of  memory,
  423.           instead of on the processor stack. This has the  effect  that  the
  424.           contents of the variable will be retained  between  calls  to  the
  425.           function. It also means that the variable  may  be  initialzed  at
  426.           compile time.
  427.     
  428.              The "register" modifier indicates to the  code  generator  that
  429.           this is a high priority variable, and should be kept where  it  is
  430.           easy to get at. Since  its  interpretation  depends  on  the  code
  431.           generator, it is often  ignored  in  simple  implementations.  See
  432.           "Functions" for a  special  use  of  "register"  when  defining  a
  433.           function.
  434.     
  435.                           eg: register unsigned count;
  436.     
  437.              Symbols declared with a preceeding '*' are assumed to be 16 bit
  438.           pointers to the declared type.
  439.     
  440.                              eg: int *pointer_name;
  441.     
  442.              Symbol names declared followed by square brackets  are  assumed
  443.           to be arrays with a number of dimensions equal to  the  number  of
  444.           '[]' pairs that follow. The size of each dimension  is  identified
  445.           by a constant value  contained  within  the  corresponding  square
  446.           brackets.
  447.     
  448.                           eg: char array_name[5][10];
  449.     MICRO-C                                                          Page: 9
  450.  
  451.  
  452.           3.2.1 Global Symbols
  453.     
  454.                 Symbols  declared  outside  of  a  function  definition  are
  455.              considered to  be  global  and  will  have  memory  permanently
  456.              reserved for them. Global symbols are defined by  name  in  the
  457.              output file, allowing other modules to access them.
  458.     
  459.                 Note that the compiler IS case  sensitive,  however  if  the
  460.              assembler you are using is NOT, you  must  be  careful  not  to
  461.              declare any global symbols with names that differ only in case.
  462.     
  463.                 All non-initialized global variables are  generated  at  the
  464.              very end of the output file, after the literal pool is  dumped.
  465.              Since non-initialized globals do not generate object code, this
  466.              allows them to be excluded from the image file when it is saved
  467.              to disk.
  468.     
  469.                 Global variables may be initialized with one or more values,
  470.              which are expressed as a single array of  integers  REGUARDLESS
  471.              of the size and shape of the variable. If more than  one  value
  472.              is expressed, '{' and '}' must be used.
  473.     
  474.                    eg: int i = 10, j[2][2] = { 1, 2, 3, 4 };
  475.     
  476.                 When arrays are declared, a null dimension may  be  used  as
  477.              the dimension size, in which case the size of  the  array  will
  478.              default to the number of initialized values.
  479.     
  480.                          eg: int array[] = { 1, 2, 3 };
  481.     
  482.                 Initialized global variables are automatically saved  within
  483.              the code image,  insuring  that  the  initial  values  will  be
  484.              available at run time. Any non-initialized elements of an array
  485.              which has been partly initialized will be set to zero.
  486.     
  487.                 Non-initialized global variables are not preset in any  way,
  488.              and will be undefined at the beginning of program execution.
  489.     
  490.           3.2.2 Local Symbols
  491.     
  492.                 Symbols declared within a function definition are  allocated
  493.              on the stack, and  exist  only  during  the  execution  of  the
  494.              function.
  495.     
  496.                 To simplify the allocation and de-allocation of stack space,
  497.              all local symbols must be declared  at  the  beginning  of  the
  498.              function before any code producing statements are encountered.
  499.     
  500.                 MICRO-C does not support initialization of non-static  local
  501.              variables in the declaration statement. Since  local  variables
  502.              have to be initialized every time the function is entered,  you
  503.              can get the same effect  using  assignment  statements  at  the
  504.              beginning of the function.
  505.     
  506.                 No type is assumed for  arguments  to  functions.  Arguments
  507.              must be explicitly declared, otherwise they will  be  undefined
  508.              within the scope of the function definition.
  509.     MICRO-C                                                          Page: 10
  510.  
  511.  
  512.           3.2.3 More Symbol Examples
  513.     
  514.             /* Global variables are defined outside of any function */
  515.             char a;                     /* 8 bit signed */
  516.             unsigned char b;            /* 8 bit unsigned */
  517.             int c;                      /* 16 bit signed */
  518.             unsigned int d;             /* 16 bit unsigned */
  519.             unsigned e;                 /* also 16 bit unsigned */
  520.             extern char f();            /* external function returning char */
  521.             static int g;               /* 16 bit signed, local to file */
  522.             int h[2] = { 1, 2 };        /* initialized array (2 ints) */
  523.     
  524.             main(a, b)                  /* "int" function containing code */
  525.             /* Function arguments are defined between function name and body */
  526.                 int a;                  /* 16 bit signed */
  527.                 unsigned char *b;       /* pointer to 8 bit unsigned */
  528.             {
  529.             /* Local variables are defined inside the function body */
  530.             /* Note that in MICRO-C, only "static" locals can be initialized */
  531.                 unsigned c;             /* 16 bit unsigned */
  532.                 static char d[5];       /* 8 bit signed, reserved in memory */
  533.                 static int e = 1;       /* 16 bit signed, initial value is 1 */
  534.             /* Function code goes here ... */
  535.                 c = 0;                  /* Initialize 'c' to zero */
  536.                 strcpy(d, "Name");      /* Initialize 'd' to "name" */
  537.             }
  538.     MICRO-C                                                          Page: 11
  539.  
  540.  
  541.        3.3 Arrays & Pointers
  542.     
  543.              When MICRO-C passes an array to a function, it actually  passes
  544.           a POINTER to the array. References to arrays which  are  arguments
  545.           are automatically performed through the pointer.
  546.     
  547.              This allows the use of pointers and arrays to be interchangable
  548.           through the context of a function call. Ie: An array passed  to  a
  549.           function may be declared and used as  a  pointer,  and  a  pointer
  550.           passed to a function may be declared and used as an array.
  551.     
  552.        3.4 Functions
  553.     
  554.              Functions are  essentially  initialized  global  symbols  which
  555.           contain executable code.
  556.     
  557.              MICRO-C accepts  any  valid  value  as  a  function  reference,
  558.           allowing  some  rather  unique  (although  non-standard)  function
  559.           calls.
  560.     
  561.           For example:
  562.     
  563.                 function();     /* call function */
  564.                 variable();     /* call contents of a variable */
  565.                 (*var)();       /* call indirect through variable */
  566.                 (*var[x])();    /* call indirect through indexed array */
  567.                 0x5000();       /* call address 0x5000 */
  568.     
  569.              Since this is a single pass compiler, operands to functions are
  570.           evaluated and pushed on the stack in the order in which  they  are
  571.           encountered, leaving the last operand closest to the  top  of  the
  572.           stack. This is the opposite order from which  many  'C'  compilers
  573.           push operands.
  574.     
  575.              For functions with a fixed number of arguments,  the  order  of
  576.           which operands  are  passed  is  of  no  importance,  because  the
  577.           compiler looks after generating  the  proper  stack  addresses  to
  578.           reference variables.  HOWEVER,  functions  which  use  a  variable
  579.           number of arguments are affected for two reasons:
  580.     
  581.           1) The location of the LAST arguments are known (as fixed  offsets
  582.              from the stack pointer) instead of the FIRST.
  583.     
  584.           2) The symbols defined as arguments  in  the  function  definition
  585.              represent the LAST arguments instead of the FIRST.
  586.     
  587.              If a function is declared as "register", it  serves  a  special
  588.           purpose and causes the accumulator to be loaded with the number of
  589.           arguments passed whenever the function is called. This allows  the
  590.           function to know how many  arguments  were  passed  and  therefore
  591.           determine the location of the first argument.
  592.     MICRO-C                                                          Page: 12
  593.  
  594.  
  595.        3.5 Structures & Unions
  596.     
  597.              Combinations of other variable  types  can  be  organized  into
  598.           STRUCTURES or UNIONS, which allow them  to  be  manipulated  as  a
  599.           single entity.
  600.     
  601.              In a structure, the  individual  items  occur  sequentially  in
  602.           memory, and the total size of the structure  is  the  sum  of  its
  603.           elements. Structures are usually  used  to  create  "records",  in
  604.           which related items are grouped together. An array  of  structures
  605.           is the common method of implementing an "in-memory" database.
  606.     
  607.              A union is similar to a structure, except that  the  individual
  608.           items are overlaid in memory, and the total size of the  union  is
  609.           the size of its largest element. Unions are usually used to  allow
  610.           a single block of memory to be accessed as different 'C'  variable
  611.           types. An example of this would be in handling a message  received
  612.           in memory, in which a "type" byte indicates how the  remainder  of
  613.           the message data should be interpreted.
  614.     
  615.              Here are some example of how structures are  defined  and  used
  616.           (unions are defined and used in an identical manner,  except  that
  617.           the word 'union' is substituted for 'struct'):
  618.     
  619.             /* Create structure named 'data' with 'a,b,c & d' as members */
  620.             struct {
  621.                 int a;
  622.                 int b;
  623.                 char c;
  624.                 char d; } data;
  625.     
  626.             /* Create structure template named 'mystruc'... */
  627.             /* No actual structure variable is defined */
  628.             struct mystruc {
  629.                 int a;
  630.                 int b;
  631.                 char c;
  632.                 char d; };
  633.     
  634.             /* Create structure named 'data' using above template */
  635.             struct mystruc data;
  636.     
  637.             /* Create structure template 'mystruc', AND define a */
  638.             /* structure variable named 'data' */
  639.             struct mystruc {
  640.                 int a;
  641.                 int b;
  642.                 char c;
  643.                 char d; } data;
  644.     MICRO-C                                                          Page: 13
  645.  
  646.  
  647.             /* Create an array of structures, a pointer to a structure */
  648.             /* and an array of pointers to a structure *
  649.             struct mystruct array[10], *pointer, *parray[10];
  650.     
  651.             /* To set value in structure variable/members */
  652.             data.a = 10;            /* Direct access */
  653.             array[1].b = 10;        /* Direct array access */
  654.             pointer->c = 'a';       /* Pointer access */
  655.             parray[2]->d = 'b';     /* Pointer array access */
  656.     
  657.             /* To read value in structure variable/members */
  658.             value = data.a;         /* Direct access */
  659.             value = data[1].b;      /* Direct array access */
  660.             value = pointer->c;     /* Pointer access */
  661.             value = parray[2]->d;   /* Pointer array access */
  662.     
  663.           3.5.1 Notes on MICRO-C structure implementation:
  664.     
  665.                 Structures and Unions as implemented in MICRO-C are  similar
  666.              to the implementation of the original UNIX  'C'  compiler,  and
  667.              are bound by similar limitations, as  well  as  a  few  MICRO-C
  668.              specific ones.  Here  is  a  list  of  major  differences  when
  669.              compared to a modern ANSI compiler:
  670.     
  671.                 All structure and member names MUST  be  unique  within  the
  672.              scope of the definition. A special case  exists,  where  common
  673.              member names may be used in  multiple  structure  templates  if
  674.              they have EXACTLY the same type and offset into the  structure.
  675.              This also saves symbol table memory, since only one copy of the
  676.              member definition is actually kept.
  677.     
  678.                 MICRO-C does NOT pass entire structures to functions on  the
  679.              stack. Like  arrays,  MICRO-C  passes  structures  by  ADDRESS.
  680.              Structure variables which are function arguments  are  accessed
  681.              through pointers. For source code compatibility with  compilers
  682.              which do pass the entire structure, if you declare the argument
  683.              as a direct (non-pointer) structure, the direct ('.')  operator
  684.              is used to dereference it, even though it is actually a pointer
  685.              reference.
  686.     
  687.                 If you  MUST  have  a  local  copy  of  the  structure,  use
  688.              something like:
  689.     
  690.                 func(sptr)
  691.                     struct mystruc *sptr;
  692.                 {
  693.                     struct mystruc data;
  694.                     memcpy(data, sptr, sizeof(data));
  695.                     ...
  696.                 }
  697.     MICRO-C                                                          Page: 14
  698.  
  699.  
  700.                 To obtain the size of a structure from  its  template  name,
  701.              use the 'struct'  keyword  in  conjunction  with  the  'sizeof'
  702.              operator.   In   the   above   example,   you   could   replace
  703.              'sizeof(data)' with 'sizeof(struct mystruc)'.
  704.     
  705.                 To obtain the size of a structure member, you  must  specify
  706.              it in the context of a structure reference with another symbol:
  707.     
  708.               sizeof(variable.member) or sizeof(variable->member)
  709.     
  710.                 NOTE: The current compiler allows almost any symbol  to  the
  711.              left of the '.' or '->' operator in a 'sizeof', however  future
  712.              versions of the compiler may insist on a structure variable  or
  713.              a pointer to structure variable.
  714.     
  715.                 Pointers to structures are internally stored as pointers  to
  716.              'char', and therefore will only increment/decrement by  1  when
  717.              ++/-- is used. To advance a pointer by the size of a structure,
  718.              use:
  719.     
  720.                          ptr += sizeof(struct mystruc)
  721.     
  722.                 The 'struct' and 'union' keywords  are  not  accepted  in  a
  723.              TYPECAST. This is most commonly used to setup a  pointer  to  a
  724.              structure. Since MICRO-C stores its pointers to  structures  as
  725.              pointers to char, you can use (char*) as the typecast, and  get
  726.              the same functionality.
  727.     
  728.                 A structure name by itself (without  '.member')  acts  in  a
  729.              manner similar to a character array name.  With  no  operation,
  730.              the address of the structure is returned. You can also use '[]'
  731.              to access  individual  bytes  in  the  structure  by  indexing,
  732.              although doing so is highly non-portable.
  733.     
  734.                 MICRO-C allows static or global structures to be initialized
  735.              in the declaration, however the initial values are read  as  an
  736.              array of bytes, and are assigned directly to  structure  memory
  737.              without regard for the type or size of its members:
  738.     
  739.                 struct mystruc data = { 0, 1, 0, 2, 3, 4 };
  740.                 /* A=0:1, B=0:2, C=3, D=4 */
  741.     
  742.                 You can use INT and CHAR to switch back  and  forth  between
  743.              word/byte initialization within the value list:
  744.     
  745.                 struct mystruct data = { int 0, 1, char 2, 3 };
  746.                 /* A=0, B=1, C=2, D=3 */
  747.     
  748.                 MICRO-C does not WORD ALIGN structure elements. When using a
  749.              processor which requires word alignment, it is the  programmers
  750.              responsibility to maintain alignment, using filler  bytes  etc.
  751.              when necessary.
  752.     MICRO-C                                                          Page: 15
  753.  
  754.  
  755.        3.6 Control Statements
  756.     
  757.              The following control statements are implemented in MICRO-C:
  758.     
  759.                 if(expression)
  760.                     statement;
  761.     
  762.                 if(expression)
  763.                     statement;
  764.                 else
  765.                     statement;
  766.     
  767.                 while(expression)
  768.                     statement;
  769.     
  770.                 do
  771.                     statement;
  772.                 while expression;
  773.     
  774.                 for(expression; expression; expression)
  775.                     statement;
  776.     
  777.                 return;
  778.     
  779.                 return expression;
  780.     
  781.                 break;
  782.     
  783.                 continue;
  784.     
  785.                 switch(expression) {
  786.                     case constant_expression :
  787.                         statement;
  788.                         ...
  789.                         break;
  790.                     case constant_expression :
  791.                         statement;
  792.                         ...
  793.                         break;
  794.                         .
  795.                         .
  796.                         .
  797.                     default:
  798.                         statement; }
  799.     
  800.                 label: statement;
  801.     
  802.                 goto label;
  803.     
  804.                 asm "...";
  805.     
  806.                 asm {
  807.                     ...
  808.                     }
  809.     MICRO-C                                                          Page: 16
  810.  
  811.  
  812.     3.6.1 Notes on Control Structures
  813.     
  814.         1)  Any "statement" may be a single statement or a compound
  815.             statement enclosed within '{' and '}'.
  816.     
  817.         2)  All three "expression"s in the "for" command are optional.
  818.     
  819.         3)  If a "case" selection does not end with "break;", it will
  820.             "fall through" and execute the following case as well.
  821.     
  822.         4)  Expressions following 'return' and 'do/while' do not have
  823.             to be contained in brackets (although this is permitted).
  824.     
  825.         5)  Label names may preceed any statement, and must be any
  826.             valid symbol name, followed IMMEDIATELY by ':' (No spaces
  827.             are allowed). Labels are considered LOCAL to a function
  828.             definition and will only be accessable within the scope
  829.             of that function.
  830.     
  831.         6)  The 'asm' statement used to implement the inline assembly
  832.             language capability of MICRO-C accepts two forms:
  833.                 asm "...";      <- Assemble single line.
  834.                 asm {           <- Assemble multiple lines.
  835.                     ...
  836.                     }
  837.     MICRO-C                                                          Page: 17
  838.  
  839.  
  840.        3.7 Expression Operators
  841.     
  842.              The following expression operators are implemented in MICRO-C:
  843.     
  844.     3.7.1 Unary Operators
  845.     
  846.         -           - Negate
  847.         ~           - Bitwise Complement
  848.         !           - Logical complement
  849.         ++          - Pre or Post increment
  850.         --          - Pre or post decrement
  851.         *           - Indirection
  852.         &           - Address of
  853.         sizeof      - Size of a object or type
  854.         (type)      - Typecast
  855.     
  856.     3.7.2 Binary Operators
  857.     
  858.         +           - Addition
  859.         -           - Subtraction
  860.         *           - Multiplication
  861.         /           - Division
  862.         %           - Modulus
  863.         &           - Bitwise AND
  864.         |           - Bitwise OR
  865.         ^           - Bitwise EXCLUSIVE OR
  866.         <<          - Shift left
  867.         >>          - Shift right
  868.         ==          - Test for equality
  869.         !=          - Test for inequality
  870.         >           - Test for greater than
  871.         <           - Test for less than
  872.         >=          - Test for greater than or equal to
  873.         <=          - Test for less than or equal to
  874.         &&          - Logical AND
  875.         ||          - Logical OR
  876.         =           - Assignment
  877.         +=          - Add to self assignment
  878.         -=          - Subtract from self assignment
  879.         *=          - Multiply by self assignment
  880.         /=          - Divide by and reassign assignment
  881.         %=          - Modular self assignment
  882.         &=          - AND with self assignment
  883.         |=          - OR with self assignment
  884.         ^=          - EXCLUSIVE OR with self assignment
  885.         <<=         - Shift left self assignment
  886.         >>=         - Shift right self assignment
  887.     MICRO-C                                                          Page: 18
  888.  
  889.  
  890.     NOTES:
  891.     
  892.         1)  The expression "a && b" returns 0 if "a" is zero, otherwise the
  893.             value of "b" is returned. The "b" operand is NOT evaluated if
  894.             "a" is zero.
  895.     
  896.         2)  The expression "a || b" returns the value of "a" if it is not 0,
  897.             otherwise the value of "b" is returned. The "b" operand is NOT
  898.             evaluated if "a" is non-zero.
  899.     
  900.     3.7.3 Other Operators
  901.     
  902.         ;           - Ends a statement.
  903.         ,           - Allows several expressions in one statement.
  904.                     + Separates symbol names in multiple declarations.
  905.                     + Separates constants in multi-value initialization.
  906.                     + Separates operands in function calls.
  907.         ?           - Conditional expression (ternary operator).
  908.         :           - Delimits labels, ends CASE and separates conditionals.
  909.         .           - Access a structure member directly.
  910.         ->          - Access a structure member through a pointer.
  911.         { }         - Defines a BLOCK of statements.
  912.         ( )         - Forces priority in expression, indicates function calls.
  913.         [ ]         - Indexes arrays. If fewer index values are given than the
  914.                       number of dimensions which are defined for the array,
  915.                       the value returned will be a pointer to the appropriate
  916.                       address.
  917.     
  918.                     Eg:
  919.                         char a[5][2];
  920.     
  921.                         a[3] returns address of forth row of two characters.
  922.                         (remember index's start from zero)
  923.     
  924.                         a[3][0] returns the character at index [3][0];
  925.     MICRO-C                                                          Page: 19
  926.  
  927.  
  928.        3.8 Inline Assembly Language
  929.     
  930.              Although 'C' is a powerful and  flexible  language,  there  are
  931.           sometimes instances where a particular operation must be  peformed
  932.           at the assembly language level. This most  often  involves  either
  933.           some processor feature for which there  is  no  corresponding  'C'
  934.           operation, or a section of very time critical code.
  935.     
  936.              MICRO-C provides access to assembly  language  with  the  'asm'
  937.           statement, which has two basic forms. The first is:
  938.     
  939.                                   asm "..." ;
  940.     
  941.              In this form, the entire  text  contained  between  the  double
  942.           quote characters (") is output as a single line to the  assembler.
  943.           Note that a  semicolon  is  required,  just  like  any  other  'C'
  944.           statement.
  945.     
  946.              Since this is a standard 'C' string, you can  use  any  of  the
  947.           "special" characters, and thus you could output multiple lines  by
  948.           using '\n' within the string. Another important characteristic  of
  949.           it being a string is that it will be protected from  pre-processor
  950.           substitution.
  951.     
  952.              The second form of the 'asm' statement is:
  953.     
  954.                                      asm {
  955.                                       ...
  956.                                        }
  957.     
  958.              In this form, all lines between '{' and '}' are output  to  the
  959.           assembler. Any text following the opening '{' (on the  same  line)
  960.           is ignored. Due to  the  unknown  characteristics  of  the  inline
  961.           assembly code, the closing '}' will only be recognized when it  is
  962.           the first non-whitespace character on a line.
  963.     
  964.              The integral pre-processor will not perform substitution on the
  965.           inline assembly code, however  the  external  pre-processor  (MCP)
  966.           will substitute in this form. This allows you to  create  assembly
  967.           language "macros" using MCP, and have parameters substituted  into
  968.           them when they are expanded:
  969.     
  970.             /*
  971.              * This macro issues a 'SETB' instruction for its parameter
  972.              */
  973.             #define setbit(bit) asm {\
  974.                 SETB bit\
  975.             }
  976.     
  977.             /*
  978.              * This macro WILL NOT WORK, since the 'bit' operand to the SETB
  979.              * instruction is contained within a string and is therefore
  980.              * protected from substitution by the pre-processor
  981.              */
  982.             #define setbit(bit) asm " SETB bit";
  983.     MICRO-C                                                          Page: 20
  984.  
  985.  
  986.        3.9 Preprocessor Commands
  987.     
  988.              The  MICRO-C  compiler  supports  the  following  pre-processor
  989.           commands. These commands are recognized only if they occur at  the
  990.           beginning of the input line.
  991.     
  992.              NOTE:  This  describes  the  limited  pre-processor  which   is
  993.           integral to the  compiler,  see  also  the  section  on  the  more
  994.           powerful external processor (MCP).
  995.     
  996.           3.9.1 #define <name> <replacement_text>
  997.     
  998.                 The "#define" command allows a global name  to  be  defined,
  999.              which will be replaced with the indicated text whenever  it  is
  1000.              encountered in the input file. This occurs prior to  processing
  1001.              by the compiler.
  1002.     
  1003.           3.9.2 #file <filename>
  1004.     
  1005.                 Sets the filename of the currently  procssing  file  to  the
  1006.              given  string.  This  command   is   used   by   the   external
  1007.              pre-processor (MCP) to insure that error messages indicate  the
  1008.              original source file.
  1009.     
  1010.           3.9.3 #include <filename>
  1011.     
  1012.                 This command causes the indicated file to be opened and read
  1013.              in as the source  text.  When  the  end  of  the  new  file  is
  1014.              encountered, processing will continue with the  line  following
  1015.              "#include" in the original file.
  1016.     
  1017.           3.9.4 #ifdef <name>
  1018.     
  1019.                 Processes the following lines (up to #else or  #endif)  only
  1020.              if the given name is defined.
  1021.     
  1022.           3.9.5 #ifndef <name>
  1023.     
  1024.                 Processes the following lines (up to #else or  #endif)  only
  1025.              if the given name is NOT defined.
  1026.     
  1027.           3.9.6 #else
  1028.     
  1029.                 Processes the following lines (up to  #endif)  only  if  the
  1030.              preceeding #ifdef or #ifndef was false.
  1031.     
  1032.           3.9.7 #endif
  1033.     
  1034.                 Terminates #ifdef and #ifndef
  1035.     
  1036.                 NOTE: The integral pre-processor does not support nesting of
  1037.              the #ifdef and #idndef constructs. If you wish  to  nest  these
  1038.              conditionals, you must use the external pre-processor (MCP).
  1039.     MICRO-C                                                          Page: 21
  1040.  
  1041.  
  1042.        3.10 Error Messages
  1043.     
  1044.              When MICRO-C detects an  error,  it  outputs  an  informational
  1045.           message indicating the type of problem encountered.
  1046.     
  1047.              The error message is preceeded by the filename and line  number
  1048.           where the error occured:
  1049.     
  1050.                            program.c(5): Syntax error
  1051.     
  1052.              In the above example, the error occured in the file "program.c"
  1053.           at line 5.
  1054.     
  1055.              The following error messages are produced by the compiler:
  1056.     
  1057.           3.10.1 Compilation aborted
  1058.     
  1059.                 The preceeding error was so severe than the compiler  cannot
  1060.              proceed.
  1061.     
  1062.           3.10.2 Constant expression required
  1063.     
  1064.                 The compiler requires a constant  expression  which  can  be
  1065.              evaluated at compile time (ie: no variables).
  1066.     
  1067.           3.10.3 Declaration must preceed code.
  1068.     
  1069.                 All local variables must be defined at the beginning of  the
  1070.              function, before any code producing statements are processed.
  1071.     
  1072.           3.10.4 Dimension table exhausted
  1073.     
  1074.                 The compiler has encountered more  active  array  dimensions
  1075.              than it can handle.
  1076.     
  1077.           3.10.5 Duplicate local: 'name'
  1078.     
  1079.                 You have declared the named  local  symbol  more  than  once
  1080.              within the same function definition.
  1081.     
  1082.           3.10.6 Duplicate global: 'name'
  1083.     
  1084.                 You have declared the named global symbol more than once.
  1085.     
  1086.           3.10.7 Expected '<token>'
  1087.     
  1088.                 The compiler  was  expecting  the  given  token,  but  found
  1089.              something else.
  1090.     
  1091.           3.10.8 Expression stack overflow
  1092.     
  1093.                 The compiler has found a more complicated expression than it
  1094.              can handle. Check that it is of  correct  syntax,  and  if  so,
  1095.              break it up into two simpler expressions.
  1096.     MICRO-C                                                          Page: 22
  1097.  
  1098.  
  1099.           3.10.9 Expression stack underflow
  1100.     
  1101.                 The compiler has made an error in  parsing  the  expression.
  1102.              Check that it is of correct syntax.
  1103.     
  1104.           3.10.10 Illegal indirection
  1105.     
  1106.                 You have attempted to perform an indirect operation ('*'  or
  1107.              '[]') on an entity which is not a pointer or array. This  error
  1108.              will also result if you attempt to index  an  array  with  more
  1109.              indices than it has dimensions.
  1110.     
  1111.           3.10.11 Illegal initialization
  1112.     
  1113.                 Local variables may not be initialized  in  the  declaration
  1114.              statement. Use assignments at the  beginning  of  the  function
  1115.              code to perform the initialization.
  1116.     
  1117.           3.10.12 Illegal nested function
  1118.     
  1119.                 You may not declare a  function  within  the  definition  of
  1120.              another function.
  1121.     
  1122.           3.10.13 Improper type of symbol: 'name'
  1123.     
  1124.                 The named  symbol  is  not  of  the  correct  type  for  the
  1125.              operation that you are attempting. Eg: 'goto' where the  symbol
  1126.              is not a label.
  1127.     
  1128.           3.10.14 Improper #else/#endif
  1129.     
  1130.                 A #else or #endif statement is out of place.
  1131.     
  1132.           3.10.15 Inconsistant member offset: 'name'
  1133.     
  1134.                 The named structure member is multiply defined,  and  has  a
  1135.              different offset from its first definition.
  1136.     
  1137.           3.10.16 Inconsistant member type: 'name'
  1138.     
  1139.                 The named structure member is multiply defined,  and  has  a
  1140.              different type from its first definition.
  1141.     
  1142.           3.10.17 Inconsistant re-declaration: 'name'
  1143.     
  1144.                 You have attempted to redefine  the  named  external  symbol
  1145.              with a type which does not match its previously declared type.
  1146.     
  1147.           3.10.18 Incorrect declaration
  1148.     
  1149.                 A statement occuring outside of a function definition is not
  1150.              a valid declaration for a function or global variable.
  1151.     MICRO-C                                                          Page: 23
  1152.  
  1153.  
  1154.           3.10.19 Invalid '&' operation
  1155.     
  1156.                 You have attempted to reference  the  address  of  something
  1157.              that has no address. This error also occurs when you attempt to
  1158.              take the address of an array without giving it a  full  set  of
  1159.              indicies. Since the address is already returned in  this  case,
  1160.              simply drop the '&'. (The error occurs because you  are  trying
  1161.              to take the address of an address).
  1162.     
  1163.           3.10.20 Macro expansion too deep
  1164.     
  1165.                 The compiler has encountered a nested macro reference  which
  1166.              is too deep to be resolved.
  1167.     
  1168.           3.10.21 Macro space exhausted
  1169.     
  1170.                 The compiler has encountered  more  macro  ("#define")  text
  1171.              than it has room to store.
  1172.     
  1173.           3.10.22 No active loop
  1174.     
  1175.                 A "continue" or "break" statement was  encountered  when  no
  1176.              loop is active.
  1177.     
  1178.           3.10.23 No active switch
  1179.     
  1180.                 A "case" or "default"  statement  was  encountered  when  no
  1181.              "switch" statement is active.
  1182.     
  1183.           3.10.24 Not an argument: 'name'
  1184.     
  1185.                 You have declared the named variable as an argument, but  it
  1186.              does not appear in the argument list.
  1187.     
  1188.           3.10.25 Non-assignable
  1189.     
  1190.                 You have attempted an operation which results in  assignment
  1191.              of a value to an entity which cannot be assigned. (eg: 1 = 2);
  1192.     
  1193.           3.10.26 Numeric constant required
  1194.     
  1195.                 The compiler requires a constant expression which returns  a
  1196.              simple numeric value.
  1197.     
  1198.           3.10.27 String space exhausted
  1199.     
  1200.                 The compiler has encountered more literal  strings  than  it
  1201.              has room store.
  1202.     
  1203.           3.10.28 Symbol table full
  1204.     
  1205.                 The compiler has encountered more symbol definitions than it
  1206.              can handle.
  1207.     MICRO-C                                                          Page: 24
  1208.  
  1209.  
  1210.           3.10.29 Syntax error
  1211.     
  1212.                 The statement shown does not follow syntax rules and  cannot
  1213.              be parsed.
  1214.     
  1215.           3.10.30 Too many active cases
  1216.     
  1217.                 The compiler has run out of space  for  storing  switch/case
  1218.              tables. Reduce the number of active "cases".
  1219.     
  1220.           3.10.31 Too many defines
  1221.     
  1222.                 The compiler has encountered more '#define' statements  than
  1223.              it can handle. Reduce the number of #defines.
  1224.     
  1225.           3.10.32 Too many errors
  1226.     
  1227.                 The compiler is aborting because of excessive errors.
  1228.     
  1229.           3.10.33 Too many includes
  1230.     
  1231.                 The compiler has encountered more  nested  "#include"  files
  1232.              than it can handle.
  1233.     
  1234.           3.10.34 Too many initializers
  1235.     
  1236.                 You have specified more initialization values than there are
  1237.              locations in the global variable.
  1238.     
  1239.           3.10.35 Type clash
  1240.     
  1241.                 You have attempted to use a  value  in  a  manner  which  is
  1242.              inconsistant with its typing information.
  1243.     
  1244.           3.10.36 Unable to open: 'name'
  1245.     
  1246.                 A "#include" command specified the named file,  which  could
  1247.              not be opened.
  1248.     
  1249.           3.10.37 Undefined: 'name'
  1250.     
  1251.                 You have referenced a name which is not defined as  a  local
  1252.              or global symbol.
  1253.     
  1254.           3.10.38 Unknown structure/member: 'name'
  1255.     
  1256.                 You have referenced a  structure  template  or  member  name
  1257.              which is not defined.
  1258.     
  1259.           3.10.39 Unreferenced: 'name'
  1260.     
  1261.                 The named  symbol  was  defined  as  a  local  symbol  in  a
  1262.              function, but was never used in that function. This error  will
  1263.              occur at the end of  the  function  definition  containing  the
  1264.              symbol declaration. It is only a warning, and  will  not  cause
  1265.              the compile to abort.
  1266.     MICRO-C                                                          Page: 25
  1267.  
  1268.  
  1269.           3.10.40 Unresolved: 'name'
  1270.     
  1271.                 The named symbol was forward  referenced  (Such  as  a  GOTO
  1272.              label), and was never defined. This error will occur at the end
  1273.              of the function definition containing the reference.
  1274.     
  1275.           3.10.41 Unterminated conditional
  1276.     
  1277.                 The end of file was encountered  when  a  "#if"  or  "#else"
  1278.              conditional block was being processed.
  1279.     
  1280.           3.10.42 Unterminated function
  1281.     
  1282.                 The  end  of  the  file  was  encountered  when  a  function
  1283.              definition was still open.
  1284.     MICRO-C                                                          Page: 26
  1285.  
  1286.  
  1287.        3.11 Quirks
  1288.     
  1289.              Due  to  its  background  as  a  highly  compact  and  portable
  1290.           compiler, and its target application in embedded systems,  MICRO-C
  1291.           deviates from standard 'C' in  some  areas.  The  following  is  a
  1292.           summary of the major infractions and quirks:
  1293.     
  1294.              When using the INTERNAL  pre-processor,  the  operands  to  '#'
  1295.           commands are parsed based on separating spaces, and any portion of
  1296.           the line not required is ignored.  In  particular,  the  '#define'
  1297.           command only accepts a definition up to  the  next  space  or  tab
  1298.           character.
  1299.     
  1300.             eg: #define APLUSONE A+1        <-- uses "A+1"
  1301.                 #define APLUSONE A +1       <-- uses "A"
  1302.     
  1303.              Comments are stripped by the token scanner, which occurs  AFTER
  1304.           the '#' commands are processed.
  1305.     
  1306.             eg: #define NULL    /* comment */   <-- uses "/*"
  1307.     
  1308.              Note that since comments can therefore be included in "#define"
  1309.           symbols, you can use "/**/" to simulate spaces between tokens.
  1310.     
  1311.             eg: #define BYTE unsigned/**/char
  1312.     
  1313.              Include filenames are not delimited by '""'  or  '<>'  and  are
  1314.           passed to the operating system exactly as entered.
  1315.     
  1316.             eg: #include \mc\stdio.h
  1317.     
  1318.              NOTE:  The  above  quirks  DO  NOT  APPLY  when  the   EXTERNAL
  1319.           pre-processor (MCP) is used.
  1320.     
  1321.              The appearance of a variable name in the argument  list  for  a
  1322.           function  declaration  serves  only  to  identify  that  variables
  1323.           location on the stack. MICRO-C will not define the variable unless
  1324.           it is explicitly declared (between the argument list and the  main
  1325.           function body). In other words, all arguments to a  function  must
  1326.           be explicitly declared.
  1327.     
  1328.              MICRO-C is more  strict  about  its  handling  of  the  ADDRESS
  1329.           operator ('&') than most other compilers. It will produce an error
  1330.           message if you attempt to take the address of  a  value  which  is
  1331.           already a fixed address (such as an array name without a full  set
  1332.           of indicies). Since an address is already produced in such  cases,
  1333.           simply drop the '&'.
  1334.     
  1335.              The 'x' in '0x' and '\x' is accepted in lower case only.
  1336.     MICRO-C                                                          Page: 27
  1337.  
  1338.  
  1339.              When operating on pointers, MICRO-C only scales  the  increment
  1340.           (++), decrement (--) and index ([]) operations to account for  the
  1341.           size of the pointer:
  1342.     
  1343.             eg: char *cptr;     /* pointer to character */
  1344.                 int  *iptr;     /* pointer to integer */
  1345.                 ++cptr;         /* Advance one character */
  1346.                 ++iptr;         /* Advance one integer */
  1347.                 cptr[10];       /* Access the tenth character */
  1348.                 iptr[10];       /* Access the tenth integer */
  1349.                 cptr += 10;     /* Advance 10 characters */
  1350.                 iptr += 10;     /* Advance ONLY FIVE integers */
  1351.     
  1352.             NOTE: A portable way to advance "iptr" by integers is:
  1353.     
  1354.                 iptr = &iptr[10];   /* Advance 10 integers */
  1355.     
  1356.              Since  structures  are  internally  represented  as  arrays  of
  1357.           "char", incrementing a pointer to a structure  will  advance  only
  1358.           one (1) byte in memory. To advance to the "next" instance  of  the
  1359.           structure, use:
  1360.     
  1361.                         ptr += sizeof(struct template);
  1362.     
  1363.              The INDEXING operator '[]' is not commutative  in  MICRO-C.  In
  1364.           other words 'array[index]' cannot be expressed as 'index[array]'.
  1365.     
  1366.              MICRO-C does  not  support  "complex"  declarations  which  use
  1367.           brackets '()' for other than function parameters. These  are  most
  1368.           often used in establishing pointers to functions:
  1369.                     int (*a)();     /* Pointer to function returning INT */
  1370.                     (*a)();         /* Call address in 'a' */
  1371.     
  1372.              Since MICRO-C allows you to call any value by following it with
  1373.           '()', you can get  the  desired  effect  in  the  above  case,  by
  1374.           declaring 'a' as a simple pointer to int, and calling it with  the
  1375.           same syntax:
  1376.                     int *a;         /* Pointer to INT */
  1377.                     (*a)();         /* Call address in 'a' */
  1378.     
  1379.              MICRO-C will not output external  declarations  to  the  output
  1380.           file  for  any  variables  or  functions  which  are  declared  as
  1381.           "extern", unless that symbol is actually  referenced  in  the  'C'
  1382.           source code. This prevents "extern" declarations in system  header
  1383.           files (such as "stdio.h") which are used as  prototypes  for  some
  1384.           library functions from causing those functions to be  loaded  into
  1385.           the  object  file.  Therefore,  any  "extern"  symbols  which  are
  1386.           referenced only by inline assembly code must be  declared  in  the
  1387.           assembly code, not by the MICRO-C "extern" statement.
  1388.     MICRO-C                                                          Page: 28
  1389.  
  1390.  
  1391.              Unlike some  'C'  compilers,  MICRO-C  will  process  character
  1392.           expressions using only  BYTE  values.  Character  values  are  not
  1393.           promoted to INT unless there is  an  INT  value  involved  in  the
  1394.           expression. This results in much more efficent code  when  dealing
  1395.           with characters, particularily  on  small  processors  which  have
  1396.           limited 16 bit instructions. Consider the statement:
  1397.     
  1398.                                  return c + 1;
  1399.     
  1400.              On some compilers, this will sign extend the character variable
  1401.           'c' into an integer value, and then ADD an integer  1  and  return
  1402.           the  result.  MICRO-C  will  ADD  the  character  variable  and  a
  1403.           character 1, and then promote the result to INT  before  returning
  1404.           it (results of expressions as  operands  to  'return'  are  always
  1405.           promoted to int).
  1406.     
  1407.              Unfortunately, programs have been written  which  rely  on  the
  1408.           automatic promotion of characters to INTs to  work  properly.  The
  1409.           most common source of problems is code  which  attempts  to  treat
  1410.           CHAR variables as UNSIGNED values (many older  compilers  did  not
  1411.           support UNSIGNED CHAR). For example:
  1412.     
  1413.                                 return c & 255;
  1414.     
  1415.              In a compiler which always evaluates character  expressions  as
  1416.           INT, the above statement will extract the value of 'c' as positive
  1417.           integer ranging from 0 to 255.
  1418.     
  1419.              In MICRO-C, ANDing a character with 255  results  in  the  same
  1420.           character, which gets promoted to an integer  value  ranging  from
  1421.           -128 to 127. To force the promotion  within  the  expression,  you
  1422.           could CAST the variable to an INT:
  1423.     
  1424.                               return (int)c & 255;
  1425.     
  1426.              The same objective can be achieved  in  a  more  efficent  (and
  1427.           correct) manner by declaring the variable 'c' as UNSIGNED CHAR, or
  1428.           by CASTing the variable to an UNSIGNED value:
  1429.     
  1430.                               return (unsigned)c;
  1431.     
  1432.              Note that this is not only more clearly shows the intent of the
  1433.           programmer, but also results is more efficent code generated.
  1434.     MICRO-C                                                          Page: 29
  1435.  
  1436.  
  1437.              A related quirk arises because most processors do not support a
  1438.           simple efficent method for adding or subtracting a  SIGNED  8  bit
  1439.           quantity and a 16 bit quantity. The code generators supplied  with
  1440.           MICRO-C make the assumption that character values being  added  or
  1441.           subtracted to/from integers will contain only POSITIVE values, and
  1442.           thus use UNSIGNED  addition/subtraction.  This  allows  much  more
  1443.           efficent code to be generated, as the carry/borrow  from  the  low
  1444.           order byte of the operation is simply propagated to the high order
  1445.           byte of the result (an operation  supported  in  hardware  by  the
  1446.           CPU).
  1447.     
  1448.              For those rare instances where you do wish  to  add/subtract  a
  1449.           potentially negative character value to/from an int, you can force
  1450.           the expression to be performed  in  less  efficent  fully  16  bit
  1451.           arithmetic by casting the character to an int.
  1452.     
  1453.                 int i;
  1454.                 char c;
  1455.                 ...
  1456.                 i += c;         /* Very efficent... C should be positive */
  1457.                 i += (int)c;    /* Less efficent... C can be negative */
  1458.     
  1459.              Read the notes at the end of the section  entitled  "Structures
  1460.           and Unions" for information on  limitations  or  differences  from
  1461.           standard 'C' in MICRO-C's implementation of structures and unions.
  1462.     MICRO-C                                                          Page: 30
  1463.  
  1464.  
  1465.     4. ADVANCED TOPICS
  1466.     
  1467.           This section provides information on the more advanced aspects  of
  1468.        MICRO-C, which  is  generally  not  needed  for  casual  use  of  the
  1469.        language.
  1470.     
  1471.        4.1 Conversion Rules
  1472.     
  1473.              MICRO-C keep track of the "type" of  each  value  used  in  all
  1474.           expressions. This type identifies certain characteristics  of  the
  1475.           value,  such  as   size   range   (8/16   bits),   numeric   scope
  1476.           (signed/unsigned), reference (value/pointer) etc.
  1477.     
  1478.              When an  operation  is  performed  on  two  values  which  have
  1479.           identical "types", MICRO-C assigns that same "type" to the result.
  1480.     
  1481.              When the  two  value  "types"  involved  in  an  operation  are
  1482.           different, MICRO-C calculates the "type" of the result  using  the
  1483.           following rules:
  1484.     
  1485.           4.1.1 Size range
  1486.     
  1487.                 If both values are  direct  (not  pointer)  references,  the
  1488.              result will be 8 bits only if  both  values  were  8  bits.  If
  1489.              either value was 16 bits, the result will be 16 bits.
  1490.     
  1491.                 If one value is a pointer, and  the  other  is  direct,  the
  1492.              result will be a pointer to the same size value as the original
  1493.              pointer.
  1494.     
  1495.                 If both values were pointers, the result will be  a  pointer
  1496.              to 16 bits only if both original  pointers  referenced  16  bit
  1497.              values. If either pointer referenced an 8 bit value, the result
  1498.              will reference an 8 bit value.
  1499.     
  1500.           4.1.2 Numeric Scope
  1501.     
  1502.                 The result of an expression is considered to be signed  only
  1503.              if both original values were signed. If  either  value  was  an
  1504.              unsigned value, the result is unsigned.
  1505.     
  1506.           4.1.3 Reference
  1507.     
  1508.                 If either of the original values was a pointer,  the  result
  1509.              will be a pointer.
  1510.     
  1511.              Note that this "calculated" result type  is  used  for  partial
  1512.           results within an expression. Whenever a symbol such as a variable
  1513.           or function is referenced, the type of that symbol is  taken  from
  1514.           its declaration, no matter what "type" of value  was  last  stored
  1515.           (variable) or returned (function).
  1516.     
  1517.              The TYPECAST  operation  may  be  used  to  override  the  type
  1518.           calculated for the result of an expression if necessary.
  1519.     MICRO-C                                                          Page: 31
  1520.  
  1521.  
  1522.        4.2 Assembly Language Interface
  1523.     
  1524.              Assembly language programs may be called from 'C' functions and
  1525.           vice versa. These programs may be in the form of  inline  assembly
  1526.           language statements in the 'C' source code, or  separately  linked
  1527.           modules.
  1528.     
  1529.              When MICRO-C calls any routine ('C'  or  assembler),  it  first
  1530.           pushes all arguments to the routine onto the processor  stack,  in
  1531.           the order in  which  they  occur  in  the  argument  list  to  the
  1532.           function. This means that the LAST argument  to  the  function  is
  1533.           LOWEST on the processor stack.
  1534.     
  1535.              Arguments are always pushed as 16 bit values. Character  values
  1536.           are extended to 16 bits, and arrays are passed as 16 bit  pointers
  1537.           to the array. (MICRO-C knows that arrays which are  arguments  are
  1538.           actually  pointers,  and  automatically  references  through   the
  1539.           pointer).
  1540.     
  1541.              After pushing the arguments, MICRO-C then generates  a  machine
  1542.           language subroutine  call,  thereby  executing  the  code  of  the
  1543.           routine.
  1544.     
  1545.              Since the compiler uses the ACCUMULATOR and INDEX REGISTER,  it
  1546.           will automatically save them (if necessary) during  processing  of
  1547.           the arguments to the function (even if no arguments are  present),
  1548.           and therefore these registers do not have to be preserved  by  the
  1549.           called routine.
  1550.     
  1551.              NOTE that any other  registers  used  by  the  code  generation
  1552.           routines (register variables etc) will not be  saved  by  MICRO-C,
  1553.           and should be preserved by called functions if their content is to
  1554.           be relied on between function calls.
  1555.     
  1556.              Once the called routine returns, the arguments are removed from
  1557.           the stack by the calling program. This usually consists of  simply
  1558.           adding the number of  bytes  pushed  as  arguments  to  the  stack
  1559.           pointer.
  1560.     
  1561.              When the called function executes, the first thing usually done
  1562.           is to push any registers which must be preserved, and  to  reserve
  1563.           space on the stack for any local variables which are required.  In
  1564.           some implementations, a "base" register may also be established to
  1565.           provide a stable reference to the local variables and arguments.
  1566.     
  1567.              It is the responsibility of the called function to  remove  any
  1568.           saved registers and local variable space from the stack before  it
  1569.           returns. If a value is to be returned to the calling  program,  it
  1570.           is expected to be in the ACCUMULATOR register.
  1571.     MICRO-C                                                          Page: 32
  1572.  
  1573.  
  1574.              Local variables in a  function  may  be  referenced  as  direct
  1575.           offsets from the "base" register or stack pointer.  Note  that  if
  1576.           the stack pointer is used, offsets must be adjusted for the number
  1577.           of bytes which are pushed and  popped  on  the  stack  during  the
  1578.           execution of the function.
  1579.     
  1580.              The address of a particular local variable is calculated as:
  1581.     
  1582.                                 "base register"
  1583.                                        -
  1584.                      (Size of all local variables in bytes)
  1585.                                        + 
  1586.                (size of all preceeding local variables in bytes)
  1587.     
  1588.                                     -- OR --
  1589.     
  1590.                                 "stack pointer"
  1591.                                        +
  1592.                    (# bytes pushed during function execution)
  1593.                                        +
  1594.                (size of all preceeding local variables in bytes)
  1595.     
  1596.              Arguments to a  function  may  also  be  referenced  as  direct
  1597.           offsets from the "base" register or stack  pointer,  in  much  the
  1598.           same way as local variables are.
  1599.     
  1600.              The address of a particular argument is calculated as:
  1601.     
  1602.                                 "base register"
  1603.                                        +
  1604.         (# bytes pushed at entry of function to preserve registers etc.)
  1605.                                        +
  1606.                  (Size of return address on stack (usually 2))
  1607.                                        +
  1608.                       (# arguments from LAST argument) * 2
  1609.     
  1610.                                     -- OR --
  1611.     
  1612.                                 "stack pointer"
  1613.                                        +
  1614.                    (# bytes pushed during function execution)
  1615.                                        +
  1616.                      (size of all local variables in bytes)
  1617.                                        +
  1618.         (# bytes pushed at entry of function to preserve registers etc.)
  1619.                                        +
  1620.                  (Size of return address on stack (usually 2))
  1621.                                        +
  1622.                       (# arguments from LAST argument) * 2
  1623.     
  1624.              NOTE: The (number of bytes pushed at entry of  function)  is  a
  1625.           function of the code generator,  and  depends  on  the  particular
  1626.           MICRO-C implementation. Examine  some  assembly  output  from  the
  1627.           compiler to determine the actual number on your system.
  1628.     MICRO-C                                                          Page: 33
  1629.  
  1630.  
  1631.              If a function has been declared  as  "register",  MICRO-C  will
  1632.           load the accumulator with  the  number  of  arguments  which  were
  1633.           passed, each time the function is called. This allows the function
  1634.           to determine the location of the first argument.
  1635.     
  1636.              The address of  the  first  argument  passed  to  a  "register"
  1637.           function may be calculated as:
  1638.     
  1639.                            (accumulator contents) * 2
  1640.                                        + 
  1641.                                 "base register"
  1642.                                        +
  1643.         (# bytes pushed at entry of function to preserve registers etc.)
  1644.                                        +
  1645.                  (Size of return address on stack (usually 2))
  1646.     
  1647.                                     -- OR --
  1648.     
  1649.                            (accumulator contents) * 2
  1650.                                        +
  1651.                                 "stack pointer"
  1652.                                        +
  1653.                    (# bytes pushed during function execution)
  1654.                                        +
  1655.                      (size of all local variables in bytes)
  1656.                                        +
  1657.         (# bytes pushed at entry of function to preserve registers etc.)
  1658.                                        +
  1659.                  (Size of return address on stack (usually 2))
  1660.     
  1661.              Global  variables  exist  at  absolute  addresses  and  may  be
  1662.           referenced directly by name from within assembler  programs.  Keep
  1663.           in mind however, that MICRO-C uses only the first 15 characters of
  1664.           a symbol's name. Also, many code generators will reduce  the  size
  1665.           of names even further, often using an algorithm  to  compress  the
  1666.           name rather than simply truncating it. For this reason,  it  is  a
  1667.           good idea to avoid using global symbol names which are longer than
  1668.           8 characters if they are to be  referenced  from  within  assembly
  1669.           language programs.
  1670.     MICRO-C                                                          Page: 34
  1671.  
  1672.  
  1673.        4.3 Compiling for ROM
  1674.     
  1675.              Assuming  the  code  generator   does   not   employ   "tricky"
  1676.           programming techniques such as self  modifying  code,  the  output
  1677.           from the compiler is entirely "clean", and may be placed  in  Read
  1678.           Only Memory (ROM).
  1679.     
  1680.              The compiler places all initialized  global  variables  in  the
  1681.           output file as part of the code image. When the program is  stored
  1682.           in ROM, those variables are also stored in ROM, and  will  not  be
  1683.           modifiable.
  1684.     
  1685.              When the program is to be placed in ROM, you may not initialize
  1686.           any variables which you intend to modify  later.  Those  variables
  1687.           must be explicitly initialized by code executed at  the  beginning
  1688.           of the program.
  1689.     
  1690.              Initialized variables which you do not intend to  modify  (such
  1691.           as tables etc.) may be initialized in the declaration, and will be
  1692.           permanently saved in the ROM as part of the static code image.
  1693.     
  1694.              The  processor  stack  pointer  must  be  set  up  before   any
  1695.           expressions are evaluated, or any function  calls  are  performed.
  1696.           One way to do this is with inline assembly statements at  the  top
  1697.           of the file.
  1698.     
  1699.              All non-initialized global variables must be  located  in  RAM.
  1700.           The compiler usually outputs all such variables at the very end of
  1701.           the compilation, just after dumping the literal pool.  The  global
  1702.           variables may be moved to RAM by  editing  the  output  file,  and
  1703.           placing an appropriate "ORG" statement at  the  beginning  of  the
  1704.           globals.
  1705.     
  1706.              You must also be sure to relocate the temporary location  which
  1707.           is defined in the startup code and runtime library  ("?temp"),  as
  1708.           well  as  any  global  variables  used  in  the  standard  library
  1709.           functions.
  1710.     MICRO-C                                                          Page: 35
  1711.  
  1712.  
  1713.     5. THE MICRO-C COMPILER
  1714.     
  1715.           The heart of the MICRO-C programming environment is the  COMPILER.
  1716.        This program reads a  file  containing  a  'C'  source  program,  and
  1717.        translates it into an equivalent assembly language program.
  1718.     
  1719.           The compiler includes its  own  limited  pre-processor,  which  is
  1720.        suitable for  compiling  programs  requiring  only  non-parameterized
  1721.        MACRO substitution, simple INCLUDE file capability, and  single-level
  1722.        CONDITIONAL processing.
  1723.     
  1724.        5.1 The MCC command
  1725.     
  1726.              When  created  using  the  'io'  routines   supplied   on   the
  1727.           distribution disk, the format of the MICRO-C Compiler command line
  1728.           is:
  1729.     
  1730.                     MCC [input_file] [output_file] [options]
  1731.     
  1732.              [input_file] is the name of  the  source  file  containing  'C'
  1733.           statements to read. If no filenames are given, MCC will read  from
  1734.           standard input.
  1735.     
  1736.              [output_file] is the name of the file to  which  the  generated
  1737.           assembly language code is written. If less than two filenames  are
  1738.           specified, MCC will write to standard output.
  1739.     
  1740.           5.1.1 Command Line Options
  1741.     
  1742.                 -c      - Includes the 'C' source code in the output file
  1743.                           as assembly language comments.
  1744.     
  1745.                 -f      - Causes the compiler to "Fold" its literal pool.
  1746.                           (Identical strings not contained in explicit
  1747.                           variables only once in memory).
  1748.     
  1749.                 -l      - Enables MCC to accept line numbers.
  1750.                           (At beginning of line, followed by ':').
  1751.     
  1752.                 -q      - Instructs MCC to be quiet, and not display the
  1753.                           startup message when it is executed.
  1754.     MICRO-C                                                          Page: 36
  1755.  
  1756.  
  1757.     6. PORTING THE COMPILER
  1758.     
  1759.           There are two major goals to accomplish when porting  the  MICRO-C
  1760.        compiler to a new machine. The first is to make the compiler  run  in
  1761.        the new environment, and the second is to make it  produce  code  for
  1762.        that environment.
  1763.     
  1764.           These two goals do not always go hand in hand. For example, it may
  1765.        be desirable to implement a CROSS COMPILER which generates code for a
  1766.        different system from that on which it runs.
  1767.     
  1768.           The usual method of porting a compiler to system A when a  version
  1769.        of the compiler is already running on system B, is to first create  a
  1770.        compiler which runs on system B, producing code for  system  A.  This
  1771.        "new" compiler may then be used to create a compiler  which  runs  on
  1772.        system A.
  1773.     
  1774.           The compiler consists of a module "compile"  which  contains,  the
  1775.        main compiler, input scanner, regular expression parser,  and  symbol
  1776.        table management routines.  This  is  the  "static"  portion  of  the
  1777.        compiler which does not change in different implementations.
  1778.     
  1779.           To create a working compiler, the above module  must  be  compiled
  1780.        and linked with an "io" module and "code"  module.  The  "io"  module
  1781.        performs the necessary initialization and I/O to allow  the  compiler
  1782.        to run in a particular  environment  (goal  #1).  The  "code"  module
  1783.        generates  the  assembly  language  output  code  for  a   particular
  1784.        environment (goal #2).
  1785.     
  1786.           The compiler uses NO system library functions, and  relies  on  NO
  1787.        system services (other  than  those  used  by  the  "io"  and  "code"
  1788.        modules). This allows the compiler to  be  ported  to  virtually  any
  1789.        system.
  1790.     
  1791.           All fixed compiler  parameters  (such  as  table  sizes  etc)  are
  1792.        contained in the header file "compile.h".  When  porting  to  systems
  1793.        with very limited RAM (less than 64k), you may have to reduce some of
  1794.        these sizes in order to get it to fit.
  1795.     
  1796.        6.1 The "io" module
  1797.     
  1798.              The "io" module required  by  the  compiler  must  contain  the
  1799.           following function definitions:
  1800.     
  1801.              The function "main()" is called by the  operating  system  when
  1802.           the MICRO-C compiler is executed. It is  responsable  for  parsing
  1803.           any parmeters and command qualifiers, opening the input and output
  1804.           files,  performing  any  other  initializations  that   might   be
  1805.           required, and then  invoking  the  function  "compile()"  with  no
  1806.           arguments. The program filename should also  be  copied  into  the
  1807.           array 'file_names' found in compile.c. The "compile"  function  is
  1808.           internal to the "compile.c" module, and  will  never  return.  For
  1809.           UNIX and other systems which support I/O redirection, "stdin"  and
  1810.           "stdout" are often used for the input and output files.
  1811.     MICRO-C                                                          Page: 37
  1812.  
  1813.  
  1814.              The function "terminate(rc)" is called when  the  compiler  has
  1815.           finished all processing and wishes to terminate. The value "rc" is
  1816.           a return code: 0 = Success, program compiled without error,  -1  =
  1817.           Compile was aborted due to severe errors, n  =  Compile  finished,
  1818.           but had 'n' errors.
  1819.     
  1820.              The function "put_chr(chr, flag)"  is  passed  a  character  to
  1821.           output, as well as a flag. The flag will always be zero  when  the
  1822.           character is being sent to the console terminal, or non-zero  when
  1823.           the character is to be written to the output file.
  1824.     
  1825.              The function "put_str(*ptr, flag)" is passed  a  pointer  to  a
  1826.           zero terminated string, which is to be written to the  console  or
  1827.           output file as determined by "flag".
  1828.     
  1829.              The function "put_num(number, flag)" is passed a 16 bit number,
  1830.           which is to be written in printable form to the console or  output
  1831.           file as determined by "flag".
  1832.     
  1833.              The function "get_lin(*ptr)" is passed a pointer to a character
  1834.           array, and should read a single line from the currently open input
  1835.           file into that array. The manifest definition  "LINE_SIZE",  found
  1836.           in "compile.h" may be used to determine the  maximum  line  length
  1837.           acceptable to the compiler. Return of a non-zero  value  indicates
  1838.           the end of file condition.
  1839.     
  1840.              The function "f_open(*ptr)" is passed a pointer to a  filename.
  1841.           The new file should be opened, and if successful,  the  old  input
  1842.           file should remain open and be "stacked", so that it can be  later
  1843.           returned to, and a non-zero value returned. A zero value indicates
  1844.           to the compiler that the file could not be opened.
  1845.     
  1846.              The  function  "f_close()"  is  responsible  for  closing   the
  1847.           currently  open  input  file,  and  returning  to  the   "stacked"
  1848.           previously open one. It receives  no  parameters.  Note:  multiple
  1849.           "opens"  may  be  stacked  -  see  the  manifest   definition   of
  1850.           "INCL_DEPTH" in the "compile.h" file.
  1851.     
  1852.           6.1.1 Notes on I/O module
  1853.     
  1854.              1) It is the responsibility of the "put" routines to  translate
  1855.                 the  NEWLINE  '\n'  (0x0a)  character  into  whatever   line
  1856.                 termination  character(s)  are  required   by   the   target
  1857.                 operating system.
  1858.     
  1859.              2) If unix "stdin"  and  "stdout"  are  not  used,  it  is  the
  1860.                 responsibility  of  "main"  to  display  appropriate   error
  1861.                 messages if the input or output files could not be opened.
  1862.     
  1863.                 Refer to  the  sample  "io"  modules  distributed  with  the
  1864.              compiler.
  1865.     MICRO-C                                                          Page: 38
  1866.  
  1867.  
  1868.        6.2 The "code" module
  1869.     
  1870.              In order to insure that MICRO-C is portable  to  virtually  any
  1871.           environment,  the  compiler  makes  few  assumptions   about   the
  1872.           processor or system software of  the  target  system.  The  "code"
  1873.           module is relied  on  to  produce  all  machine  instructions  and
  1874.           assembler directives written to the output file.
  1875.     
  1876.              The only two real "assumptions" made about the target processor
  1877.           are:
  1878.     
  1879.           1) It is assumed that the target processor  has  an  "accumulator"
  1880.              register in which all math operations are performed,  and  that
  1881.              the  lower  8  bits  of   this   register   may   be   accessed
  1882.              independantly.
  1883.     
  1884.           2) It is  assumed  that  the  target  processor  has  one  "index"
  1885.              register which may be loaded with a  16  bit  value,  and  that
  1886.              memory references may be made indirectly through this register.
  1887.     
  1888.              If the target processor does not support the above features, it
  1889.           may be possible to write a code generator for it using some  other
  1890.           features of the processor.
  1891.     
  1892.              For example, if an "index" register  does  not  exist,  it  may
  1893.           often be implemented using two bytes of reserved memory.
  1894.     
  1895.              The code  generation  module  required  by  the  compiler  must
  1896.           contain the following function definitions:
  1897.     
  1898.              The function  "do_comment(*ptr)"  is  passed  a  pointer  to  a
  1899.           character string, which is should write to the output  file  as  a
  1900.           single line COMMENT (used by '-c' option). This function  is  also
  1901.           called with a NULL (0)  pointer  anytime  the  compiler  wants  to
  1902.           insure that the code generator is reset to begin  a  new  line  of
  1903.           output.
  1904.     
  1905.              The function "do_asm(*ptr)" is passed a pointer to a  character
  1906.           string, which it should write to the output file as a single  line
  1907.           STATEMENT (used for inline assembly language).
  1908.     
  1909.              The function "def_module()"  is  called  at  the  beginning  of
  1910.           compilation, before any other code generator functions are called.
  1911.           It is used to output any pre-amble needed by the assembler.
  1912.     
  1913.              The function "end_module()"  is  called  at  the  very  end  of
  1914.           compilation, and is the last code generator function called. It is
  1915.           used to output any post-amble needed by the assembler.
  1916.     MICRO-C                                                          Page: 39
  1917.  
  1918.  
  1919.              The function "def_static(symbol, ssize)"  is  passed  am  index
  1920.           into the compiler symbol tables for a global  variable,  which  is
  1921.           about to be initialized  as  static  storage.  The  call  to  this
  1922.           function will be immediately followed by a call  to  "init_static"
  1923.           or "end_static". The "ssize" parameter will  be  non-zero  if  the
  1924.           variable is a structure or union.
  1925.     
  1926.              The "init_static(token, value,  word)"  function  is  passed  a
  1927.           token and value, with which it should initialize a single  element
  1928.           of static storage. The "word" flag will be non-zero if  the  value
  1929.           is a 16 bit element. Only the "constant" tokens  (NUMBER,  STRING,
  1930.           LABEL) and SYMBOL need be handled by this routine. When SYMBOL  is
  1931.           used,  the  constant  ADDRESS  of  the  passed  symbol  should  be
  1932.           generated.
  1933.     
  1934.              The  "end_static()"  function  is  called  to   terminate   the
  1935.           definition of static storage.
  1936.     
  1937.              NOTE: "init_static"  should  not  rely  on  "def_static"  being
  1938.           called first,  since  it  is  also  called  immediately  following
  1939.           "def_label" to define "switch" tables (See "do_switch"). After the
  1940.           table  is  defined,  the  compiler  will  call  "end_static()"  to
  1941.           terminate the initialization and set up for the next.
  1942.     
  1943.              The function "def_global(symbol, size)" is called at the end of
  1944.           the compile, once for each non-static global  variable  which  was
  1945.           defined. The "size" paremeter indicates the  number  of  BYTES  of
  1946.           memory to be reserved for that variable.
  1947.     
  1948.              The function "def_extern(symbol)" is called at the end  of  the
  1949.           compile, once  for  each  unresolved  external  symbol  which  was
  1950.           defined. This routine should examine the type of  the  symbol  and
  1951.           output the appropriate assembler directives  to  allow  it  to  be
  1952.           referenced in another module.
  1953.     
  1954.              The "def_func(symbol, size)"  routine  is  called  to  start  a
  1955.           function definition. The "symbol" parameter is an index  into  the
  1956.           compiler symbol tables for the function entry being  defined.  The
  1957.           "size" parameter indicates how many  bytes  of  memory  should  be
  1958.           allocated  on  the  stack  for  local  variables.  When   defining
  1959.           "register" functions, care must  be  taken  that  the  entry  code
  1960.           preserves the contents of the accumulator.
  1961.     
  1962.              The "end_func()" routine is  called  to  terminate  a  function
  1963.           definition.  It  should  remove  anything  placed  on  the   stack
  1964.           (including the local variable space allocated by "def_func"),  and
  1965.           terminate the function with a "return" instruction.
  1966.     
  1967.              The "def_label(label)" function is called whenever the compiler
  1968.           wants to generate a label in the output file. Each label generated
  1969.           by the compiler is identified by a 16 bit unsigned number.  It  is
  1970.           up to the code generator to generate a unique label  suitable  for
  1971.           the target assembler.
  1972.     MICRO-C                                                          Page: 40
  1973.  
  1974.  
  1975.              The "def_literal(*ptr, size)" function is called at the end  of
  1976.           the  compile,  just  before  non-initialized  global  symbols  are
  1977.           generated. This routine is  given  a  pointer  to  the  compiler's
  1978.           "literal pool", which contains all the character strings  occuring
  1979.           during the compilation. The "size" parameter  indicates  how  many
  1980.           characters are in the pool. This pool must  be  generated  in  the
  1981.           output file as a string of byte constants.
  1982.     
  1983.              The "call(token, value,  type,  clean)"  function  is  used  to
  1984.           generate  a  machine  language  subroutine  call  to  the   entity
  1985.           indicated by the "token, value & type" parameters (See later). The
  1986.           "clean" parameter indicates how many entries were pushed onto  the
  1987.           stack as arguments, which should be removed following the function
  1988.           call.  Note:  Since  stack  entries  are   TWO   bytes   in   most
  1989.           implementations, the "clean" value must be multiplied  by  two  to
  1990.           get the actual number of bytes to be removed from the stack.
  1991.     
  1992.              The function "jump(label,  ljmp)"  is  called  to  generate  an
  1993.           unconditional jump instruction to the indicated compiler generated
  1994.           label. The "ljmp" flag will be set to zero if the jump  references
  1995.           code within the same expression from which it  is  generated,  and
  1996.           non-zero if one or more statements may occur between the jump  and
  1997.           the destination label. This allows  the  code  generator  to  take
  1998.           advantage of "short" jumps if they are available on the target.
  1999.     
  2000.              The function "jump_if(cond, label, ljmp) is called to  generate
  2001.           a conditional jump to a compiler generated label. The "cond" value
  2002.           indicates the condition: FALSE = Jump if accumulator is zero, TRUE
  2003.           = jump if accumulator is non-zero. Remaining  parameters  are  the
  2004.           same as above.
  2005.     
  2006.              The function "do_switch(label)" is  passed  the  address  of  a
  2007.           "switch" table, which contains 16  bit  entries,  and  is  of  the
  2008.           following format:
  2009.     
  2010.                         label-1, value-1, label-2, value-2, ....
  2011.                         label-n, value-n, 0, default_label
  2012.     
  2013.              This routine should search the table for the value currently in
  2014.           the accumulator, and if found, it  should  proceed  to  the  label
  2015.           associated with that value. If the value is not found  before  the
  2016.           end of the table is encountered (identified by a  label  value  of
  2017.           zero), execution should  proceed  at  the  address  identified  by
  2018.           "default_label".
  2019.     
  2020.              The "index_ptr(token, value, type)"  routine  should  load  the
  2021.           index register with the value  of  the  entity  indicated  by  the
  2022.           "token, value & type" parameters. This will always  be  a  16  bit
  2023.           wide quantity.
  2024.     MICRO-C                                                          Page: 41
  2025.  
  2026.  
  2027.              The "index_adr(token, value, type)"  routine  should  load  the
  2028.           index register with the 16 bit address of the  object  represented
  2029.           by "token, value & type". The only tokens passed to  this  routine
  2030.           are SYMBOL and ION_STACK.
  2031.     
  2032.              The routine "expand(type)" is called following  the  evaluation
  2033.           of expressions in "return" and "switch" statements, and is used to
  2034.           insure that the result is a 16 bit value.
  2035.     
  2036.              The routine "accop(oper, type)" is  called  to  perform  a  "no
  2037.           operand" operation on the accumulator. See "compile.h" for a  list
  2038.           of these operations. The "type" passed indicates the type of value
  2039.           expected as a result.
  2040.     
  2041.              The routine "accval(oper, rtype, token, value, type)" is called
  2042.           to perform a "one  operand"  operation  on  the  accumulator.  See
  2043.           "compile.h" for a list of these operations. "rtype" indicates  the
  2044.           type of value expected as a result. "token",  "value"  and  "type"
  2045.           indicate  the  location  and  type  of  operand  which  is   being
  2046.           processed.
  2047.     MICRO-C                                                          Page: 42
  2048.  
  2049.  
  2050.           6.2.1 Notes on code generation
  2051.     
  2052.                 The meaning of the individual bits  in  the  16  bit  "type"
  2053.              value which is passed to many of the code generation  routines,
  2054.              is documented in the "compile.h" file.
  2055.     
  2056.                 The meaning of "token"  is  documented  in  the  "compile.h"
  2057.              file. For  each  type  of  "token",  "value"  has  a  different
  2058.              meaning:
  2059.     
  2060.                 Token           Meaning of "value"
  2061.                 ----------------------------------------------------------
  2062.                 NUMBER          The numeric value of the constant.
  2063.                 STRING          The offset into the literal pool.
  2064.                 LABEL           The value of the compiler generated label.
  2065.                 SYMBOL          Index into global symbol tables.
  2066.                 All others      Undefined.
  2067.     
  2068.                 When token is a SYMBOL, the "value" passed is used to  index
  2069.              into the global symbol tables (contained within  the  "compile"
  2070.              module) to  determine  information  about  the  variable.  When
  2071.              "value" is  less  than  the  value  of  the  compiler  internal
  2072.              variable 'global_top', the symbol is GLOBAL,  otherwise  it  is
  2073.              LOCAL:
  2074.     
  2075.                 s_name[value]   - Name of symbol (up to SYMBOL_SIZE chars)
  2076.                 s_type[value]   - Type of symbol (bits defined in "compile.h").
  2077.                 s_index[value]  - Variable index:
  2078.                         Local (auto):   Stack offset from def_func.
  2079.                         Argument:       Stack offset from last argument pushed.
  2080.                         Static:         Unique variable number for symbol.
  2081.     
  2082.                 When calculating the stack offset for  ARGUMENTs,  you  must
  2083.              add the number of bytes placed on the stack when  the  function
  2084.              was called. This  includes  the  local  variables,  the  return
  2085.              address, and any other values that "def_func" might push.
  2086.     
  2087.                 There are two popular ways of  providing  addressability  to
  2088.              local variables:
  2089.     
  2090.                 If the processor has many registers, you can reserve one  as
  2091.              a "base" pointer, and point it at the top of the stack when the
  2092.              function  is  entered.  This  allows  local  variables  to   be
  2093.              referenced as negative offsets from that "base"  register,  and
  2094.              arguments to be referenced as positive offsets  from  it.  This
  2095.              approach also allows the stack to  be  restored  directly  from
  2096.              this base  register  when  the  function  terminates.  See  the
  2097.              section on assembly language interfacing.
  2098.     
  2099.                 Another approach is to have the  code  generator  "remember"
  2100.              exactly how many bytes have been pushed onto  the  stack  since
  2101.              "def_func", and adjust the offsets it generates  based  on  the
  2102.              stack contents. This has  the  advantage  of  not  tying  up  a
  2103.              register.
  2104.     MICRO-C                                                          Page: 43
  2105.  
  2106.  
  2107.                 If you intend to use the MICRO-C Source Linker (SLINK), then
  2108.              you have to insure that whatever variable you use to  reference
  2109.              the "literal pool" qualifies as a "compiler  generated"  label,
  2110.              allowing SLINK to adjust it when processing the  source  files.
  2111.              Compiler  generated  labels  normally  consist  of   a   single
  2112.              character (such as '?'), followed by a  decimal  number.  Since
  2113.              the compiler begins generating its labels with the  value  '1',
  2114.              you may safely use '0' as the literal pool variable (Ie: '?0').
  2115.     
  2116.                 It is the responsibility of the code generator to keep track
  2117.              of the validity  of  the  upper  8  bits  of  the  accumulator.
  2118.              Appropriate sign extension or clearing of  high  bits  must  be
  2119.              performed as necessary to convert signed and unsigned character
  2120.              values when 16 bit results when required.
  2121.     
  2122.                 To improve the effiency of conditional statements, the  code
  2123.              generator should keep track of the validity of the "zero"  flag
  2124.              in  the  processor's  condition  code  register,  and  generate
  2125.              appropriate  "test"  instructions  only  if  necessary  when  a
  2126.              conditional jump is compiled.
  2127.     
  2128.                 For  processors  not  supporting   operations   with   stack
  2129.              contents, the "ON_STACK" and "ION_STACK" tokens may implemented
  2130.              by first popping the top of the  stack  into  a  register.  The
  2131.              "ISTACK_TOP" token is a special case, because  the  address  on
  2132.              the top of the stack must  not  be  lost.  This  token  may  be
  2133.              efficiently implemented, because "ISTACK_TOP" is only used  for
  2134.              read/write operations to  a  stacked  calculated  address.  For
  2135.              example:
  2136.     
  2137.                             array1[i] += array2[i];
  2138.     
  2139.                 This statement calculates the address of "array1[i]" (in the
  2140.              index register). Since the "index" register is  again  used  in
  2141.              calculating the address of "array2[i]", the first "index"  will
  2142.              be placed on the stack. Once the contents  of  "array2[i]"  are
  2143.              retrieved, it  will  be  added  using  "ISTACK_TOP",  and  then
  2144.              re-stored using "ION_STACK".
  2145.     
  2146.                 The "ISTACK_TOP" token may  thus  pop  the  address  into  a
  2147.              register, and set a flag indicating to the code generator  that
  2148.              the next "ION_STACK" token  is  to  go  through  that  register
  2149.              rather than the top of the stack. Note that since an arithmetic
  2150.              operation may be performed between the two references, you must
  2151.              not use a register which is  modified  in  code  generated  for
  2152.              arithmetic operations.
  2153.     
  2154.                 Refer to the sample code  generators  distributed  with  the
  2155.              compiler.
  2156.     MICRO-C                                                          Page: 44
  2157.  
  2158.  
  2159.        6.3 The "compile" module
  2160.     
  2161.              The "compile" module  contains  the  main  statement  analyser,
  2162.           input  scanner,  expression  parser  and  symbol  table  managment
  2163.           routines for the MICRO-C compiler. This module is  common  to  all
  2164.           implementations, and should NOT require changes in most cases. The
  2165.           source code for this module is contained in the  "compile.c"  file
  2166.           on your distribution diskette, and may  be  examined  for  insight
  2167.           into the internal operation of the compiler.
  2168.     
  2169.              This module must be compiled and linked with your I/O and  code
  2170.           generation routines to  generate  a  complete  executable  MICRO-C
  2171.           compiler.
  2172.     
  2173.              To test your code generator,  the  file  "test.c"  is  provided
  2174.           which when compiled using the new compiler, performs a  number  of
  2175.           simple tests  to  verify  your  code  generator.  This  is  not  a
  2176.           comprehensive analysis, as  it  makes  no  assumptions  about  the
  2177.           processor, however, it provides a good indication that  your  code
  2178.           generator is on the right track.
  2179.     
  2180.              A number of fixed parameters to the  compiler  (such  as  table
  2181.           sizes etc.) are contained in the header file "compile.h". The most
  2182.           common reason for changing  these  parameters  is  to  reduce  the
  2183.           memory requirements, in order to get  MICRO-C  to  fit  into  very
  2184.           small systems.
  2185.     
  2186.              If any of the parameters in "compile.h" are to be changed,  you
  2187.           must  make  the  changes  BEFORE  compiling  any  of  the  modules
  2188.           (compile, io or codegen).
  2189.     
  2190.              The file  "tokens.h"  contains  symbolic  definitions  for  the
  2191.           tokens parsed by the  compiler,  the  text  of  which  is  in  the
  2192.           character array variable "tokens". If you make any changes to this
  2193.           token table, MAKE SURE that the contents of the "tokens"  variable
  2194.           and the "tokens.h" file agree, otherwise, you will end up  with  a
  2195.           compiler for a very strange language.
  2196.     
  2197.           6.3.1 **NOTE for 32 bit compiler users
  2198.     
  2199.                 COMPILE.C has one potential portability  problem  if  it  is
  2200.              compiled on a machine where  an  'int'  is  not  16  bits.  The
  2201.              routine "skip_comment()" uses a 16 bit 'int' to hold  the  last
  2202.              two characters from the source file, in order to test  for  the
  2203.              "/*" and "*/" sequences.
  2204.     
  2205.                 If an 'int' can contain more that TWO characters,  you  must
  2206.              modify this function so that only the last two  characters  are
  2207.              retained.
  2208.     MICRO-C                                                          Page: 45
  2209.  
  2210.  
  2211.        6.4 Porting without a linker
  2212.     
  2213.              It is possible to port MICRO-C using a system  which  does  not
  2214.           support a linker. To do this, you must concatinate all the  source
  2215.           files "compile.c", "code.c" and "io.c" into  one  large  file  (in
  2216.           that order), and compile them all as one program.
  2217.     
  2218.              When this is done, the ".h" include files need only be included
  2219.           once, and external definitions  of  variables  occuring  in  other
  2220.           source files should not  be  used.  The  source  programs  on  the
  2221.           distribution disk all contain conditional  compilation  statements
  2222.           (#ifndef), which only perform the necessary #include and  external
  2223.           definition statements when compiling as a single file.
  2224.     
  2225.        6.5 Optimization Techniques
  2226.     
  2227.              The MICRO-C compiler performs the following machine independant
  2228.           optimizations of the output file:
  2229.     
  2230.           1) All constant expressions are evaluated  at  compile  time,  and
  2231.              expressed as a single constant value in the output code.
  2232.     
  2233.           2) Commutative operations may be reversed  to  take  advantage  of
  2234.              partial results  already  in  the  accumulator.  This  includes
  2235.              operations which have an equivalent reverse (ie: "a>(b-1)"  may
  2236.              become "(b-1)<a").
  2237.     
  2238.           3) Redundant jumps as a result of "return" or  "break"  statements
  2239.              are suppressed.
  2240.     
  2241.           4) The sense of jumps in conditional statements are  reversed  for
  2242.              logically negated expressions, code for '!' is  only  generated
  2243.              if the value returned by that operator is actually used.
  2244.     
  2245.           5) Jumps between code generated within  a  single  expression  are
  2246.              flagged as "short".
  2247.     
  2248.              Although the MICRO-C compiler produces fairly  reasonable  code
  2249.           for the  processor  model  it  uses,  that  model  is  necessarily
  2250.           limited, in order that it might fit a  large  number  of  physical
  2251.           targets. There are  several  simple  optimizations  which  may  be
  2252.           performed to further enhance the code generated by the compiler in
  2253.           a specific implementation.
  2254.     MICRO-C                                                          Page: 46
  2255.  
  2256.  
  2257.           6.5.1 Register Usage
  2258.     
  2259.                 MICRO-C assumes a single accumulator,  and  a  single  index
  2260.              register.  Additional  terms  in  complicated  expressions  are
  2261.              handled by placing temporary results on  the  processor  stack,
  2262.              and re-using those registers. All data placed on the  stack  is
  2263.              accessed on a "last in - first out" basis.
  2264.     
  2265.                 If the target processor has a  full  compliment  of  general
  2266.              purpose registers, an optimization may be performed  by  simply
  2267.              selecting another general purpose register as  the  accumulator
  2268.              or index register instead of placing the value  on  the  stack.
  2269.              The code generator must  keep  track  of  the  order  in  which
  2270.              registers are selected, and which register represents the "top"
  2271.              of the stack. If the number  of  values  "pushed"  exceeds  the
  2272.              number of available registers, the "oldest" register should  be
  2273.              placed on the stack, thereby allowing it to be re-used.
  2274.     
  2275.           6.5.2 Jump Optimization
  2276.     
  2277.                 Although MICRO-C identifies jumps to instructions which span
  2278.              more than one expression as "long",  often  the  addresses  are
  2279.              close enough together that short jumps may  actually  be  used.
  2280.              This optimization is particularily useful for  processors  such
  2281.              as the 8086, which does not support "long"  conditional  jumps,
  2282.              and therefore must simulate them with a short conditional  jump
  2283.              of the opposite sense around a long unconditional jump.
  2284.     
  2285.           6.5.3 Redundant Load Elimination
  2286.     
  2287.                 Since  MICRO-C  evaluates  and  processes   each   statement
  2288.              individually, it  does  not  carry  partial  results  from  one
  2289.              statement to another.
  2290.     
  2291.                 Consider the following statements:
  2292.     
  2293.                                  a = x;
  2294.                                  b = a + 1;
  2295.     
  2296.                 MICRO-C generates the code:
  2297.     
  2298.                                  LOAD x
  2299.                                  STORE a
  2300.                                  LOAD a
  2301.                                  ADD 1
  2302.                                  STORE b
  2303.     
  2304.                 An optimization may be performed  by  recognizing  that  the
  2305.              second "load" instruction is redundant, and can be  eliminated.
  2306.              Note: A more efficent (but less readable)  way  of  coding  the
  2307.              above statements which would result in the latter code  without
  2308.              optimization is:
  2309.     
  2310.                                  b = (a = x) + 1;
  2311.     MICRO-C                                                          Page: 47
  2312.  
  2313.  
  2314.           6.5.4 Peephole Optimization
  2315.     
  2316.                 Consider the statement:
  2317.     
  2318.                                  a = *++ptr;
  2319.     
  2320.                 MICRO-C generates the code:
  2321.     
  2322.                                  LOAD ptr
  2323.                                  INCREMENT
  2324.                                  STORE ptr
  2325.                                  MOVE ACCUMULATOR TO INDEX
  2326.                                  LOAD [INDEX]
  2327.                                  STORE a
  2328.     
  2329.                 For a processor supporting  a  rich  set  of  direct  memory
  2330.              addressing modes, the above sequence can be shortened to:
  2331.     
  2332.                                  INCREMENT_MEMORY ptr
  2333.                                  LOAD [ptr]
  2334.                                  STORE a
  2335.     
  2336.                 One of the most  successful  techniques  of  optimizing  the
  2337.              output code is also one of the simplest.  Known  as  "peephole"
  2338.              optimization, the method consists of keeping a  window  of  the
  2339.              last few instructions generated,  and  scanning  the  list  for
  2340.              known patterns every time a new instruction is added to it.
  2341.     
  2342.                 As long as the instructions in the list at  least  partially
  2343.              match one or more  of  the  "predefined"  patterns,  additional
  2344.              instructions are collected  until  either  a  complete  pattern
  2345.              match occurs, or all known patterns are eliminated.
  2346.     
  2347.                 If no matches occur, the "oldest" instruction is written  to
  2348.              the output file, and the next one  becomes  the  first  in  the
  2349.              "window".
  2350.     
  2351.                 Whenever a pattern is discovered, it is replaced  by  a  new
  2352.              series of instructions which perform the same function, but  in
  2353.              a more efficent manner.
  2354.     
  2355.                 The new instruction sequences  are  replaced  on  the  list,
  2356.              which may then be  again  scanned,  allowing  further  possible
  2357.              reductions to be discovered.
  2358.     
  2359.                 Handling of labels in the "window" and  their  corresponding
  2360.              placement in the output file must be carefully done,  in  order
  2361.              to preserve the "logical" context of the original code.
  2362.     MICRO-C                                                          Page: 48
  2363.  
  2364.  
  2365.     7. THE MICRO-C PREPROCESSOR
  2366.     
  2367.           The MICRO-C Preprocessor is a source code filter,  which  provides
  2368.        greater capabilities than the preprocessor which is integral  to  the
  2369.        MICRO-C compiler. It has been implemented as a  stand  alone  utility
  2370.        program which processes the source code before it is compiled.
  2371.     
  2372.           Due to the higher complexity of  this  preprocessor,  it  operates
  2373.        slightly slower than the the integral MICRO-C preprocessor.  This  is
  2374.        mainly due to the fact that it reads each line from the file and then
  2375.        copies it to a new line while performing the macro substitution. This
  2376.        is necessary since each macro may contain parameters  which  must  be
  2377.        replaced "on the fly" when it is referenced.
  2378.     
  2379.           The integral MICRO-C preprocessor is very FAST,  because  it  does
  2380.        not copy the input line. When it encounters a '#define'd  symbol,  it
  2381.        simply adjusts the input scanner pointer to point to  the  definition
  2382.        of that symbol.
  2383.     
  2384.           Keeping the extended preprocessor as a stand alone utility  allows
  2385.        you  to  choose  between  greater   MACRO   capability   and   faster
  2386.        compilation. It also allows the system to continue  to  run  on  very
  2387.        small hardware platforms.
  2388.     
  2389.           The additional capabilities of the extended preprocessor are:
  2390.     
  2391.             - Parameterized MACROs.
  2392.     
  2393.             - Multiple line MACRO's.
  2394.     
  2395.             - Nested conditionals.
  2396.     
  2397.             - Ability to undefine MACRO symbols.
  2398.     
  2399.             - Library reference in include file names.
  2400.     MICRO-C                                                          Page: 49
  2401.  
  2402.  
  2403.        7.1 The MCP command
  2404.     
  2405.              The format of the MICRO-C Preprocessor command line is:
  2406.     
  2407.                     MCP [input_file] [output_file] [options]
  2408.     
  2409.              [input_file] is the name of  the  source  file  containing  'C'
  2410.           statements to read. If no filenames are given, MCP will read  from
  2411.           standard input.
  2412.     
  2413.              [output_file] is the name of the file to  which  the  processed
  2414.           source code is written. If less than two filenames are  specified,
  2415.           MCP will write to standard output.
  2416.     
  2417.           7.1.1 Command Line Options
  2418.     
  2419.                 MCP accepts the following command line [options]:
  2420.     
  2421.                 -c      - Instructs MCP to keep comments from  the input
  2422.                           file (except for those in '#' statements which
  2423.                           are always removed). Normally, MCP will remove
  2424.                           all comments.
  2425.     
  2426.                 -l      - Causes the output file to contain line numbers.
  2427.                           Each line in the output file will be  prefixed
  2428.                           with the line number of the  originating  line
  2429.                           from the input file.
  2430.     
  2431.                 l=path  - Defines the directory path which will be taken
  2432.                           to reference  "library"  files when  '<>'  are
  2433.                           used around an  '#include'  file name.  Unless
  2434.                           otherwise specified, the path defaults to:
  2435.                                         '\mc'
  2436.     
  2437.                 -q      - Instructs MCP to be quiet, and not display the
  2438.                           startup message when it is executed.
  2439.     
  2440.           <name>=<text> - Pre-defines a non-parameterized macro  of  the
  2441.                           specified <name> with the string value <text>.
  2442.     MICRO-C                                                          Page: 50
  2443.  
  2444.  
  2445.        7.2 Preprocesor Commands
  2446.     
  2447.              The following commands are recognized by the MCP utility,  only
  2448.           if they occur at the beginning of the source file line:
  2449.     
  2450.           7.2.1 #define <name>(parameters) <replacement text>
  2451.     
  2452.                 Defines a global macro name which will be replaced with  the
  2453.              indicated <replacement text> wherever it occurs in  the  source
  2454.              file.
  2455.     
  2456.                 Macro  names  may  be  any  length,  and  may  contain   the
  2457.              characters 'a'-'z', 'A'-'Z', '0'-'9' and '_'.  Names  must  not
  2458.              begin with the characters '0'-'9'.
  2459.     
  2460.                 If the macro name is IMMEDIATELY followed by a list of up to
  2461.              10 parameter names contained in brackets, those parameter names
  2462.              will be substituted with parameters passed to the macro when it
  2463.              is referenced. Parameter names follow the same rules  as  macro
  2464.              names.
  2465.     
  2466.                      eg: #define min(a, b) (a < b ? a : b)
  2467.     
  2468.                 If any spaces exist between the macro name and  the  opening
  2469.              '(', the macro will not be  parameterized,  and  all  following
  2470.              text (including '(' and ')') will be  entered  into  the  macro
  2471.              definition.
  2472.     
  2473.                 If the very last character of a  macro  definition  line  is
  2474.              '\', MCP will continue the definition with the next  line  (The
  2475.              '\' is not included). Pre-processor statements included as part
  2476.              of a macro definition will not be processed by MCP, but will be
  2477.              passed on and handled by the integral MICRO-C preprocessor.
  2478.     
  2479.           7.2.2 #undef <symbol>
  2480.     
  2481.                 Undefines the named macro symbol. further references to this
  2482.              symbol will not be replaced.
  2483.     
  2484.                 NOTE: With MCP, macro definitions operate on a STACK. IE: If
  2485.              you define a macro  symbol,  and  then  re-define  it  (without
  2486.              '#undef'ing it first), subsequently '#undef'ing it  will  cause
  2487.              it to revert to its  previous  definition.  A  second  '#undef'
  2488.              would then cause it to be completely undefined.
  2489.     MICRO-C                                                          Page: 51
  2490.  
  2491.  
  2492.           7.2.3 #forget <symbol>
  2493.     
  2494.                 Similar  to  '#undef',  except  that  the  symbol  and   ALL
  2495.              SUBSEQUENTLY DEFINED SYMBOLS will be undefined.
  2496.     
  2497.                 Useful for releasing any local symbols (used only  within  a
  2498.              single include file).
  2499.     
  2500.                 For example:
  2501.     
  2502.                         #define GLOBAL "xxx"    /* first global symbol */
  2503.                             ...                 /* more globals */
  2504.                         #define LOCAL   "xxx"   /* first local symbol */
  2505.                             ...                 /* more locals */
  2506.                         /* body of include file goes here */
  2507.                         #forget LOCAL           /* release locals */
  2508.     
  2509.           7.2.4 #ifdef <symbol>
  2510.     
  2511.                 Causes the following lines (up to '#else' of '#endif') to be
  2512.              processed and included in the source file  only  if  the  named
  2513.              symbol is defined as a macro.
  2514.     
  2515.           7.2.5 #ifndef <symbol>
  2516.     
  2517.                 Causes the following lines (up to '#else' of '#endif') to be
  2518.              processed and included in the source file  only  if  the  named
  2519.              symbol is NOT defined as a macro.
  2520.     
  2521.                 NOTE: '#ifdef/#ifndef#else/#endif' may be nested.
  2522.     
  2523.           7.2.6 #else
  2524.     
  2525.                 Toggles the state of the "if_flag", controlling  conditional
  2526.              processing. Only has effect in the highest level  of  suspended
  2527.              processing. IE: Nested conditionals will work properly.
  2528.     
  2529.                 If the previous  '#ifdef/#ifndef'  failed,  processing  will
  2530.              begin again following the '#else'.
  2531.     
  2532.                 If the previous '#ifdef/#ifndef' passed, processing will  be
  2533.              suspended until the '#endif' is encountered.
  2534.     
  2535.                 NOTE: Since '#else' acts as a toggle, it may be used outside
  2536.              of any '#ifdef/#ifndef' to unconditionally  suspend  processing
  2537.              up to '#endif'. You can also use multiple '#else's in a  single
  2538.              conditional,  to  swap  back  and  forth   between   true/false
  2539.              processing without re-testing the condition.
  2540.     
  2541.           7.2.7 #endif
  2542.     
  2543.                 Resets  the  "if_flag"  controlling  conditionals,   causing
  2544.              processing to resume. Only has effect in the highest  level  of
  2545.              suspended  processing.  IE:  Nested  conditionals   will   work
  2546.              properly.
  2547.     MICRO-C                                                          Page: 52
  2548.  
  2549.  
  2550.           7.2.8 #include <filename>
  2551.     
  2552.                 Causes MCP to open the named file and include  its  contents
  2553.              as part of the input source.
  2554.     
  2555.                 If the filename is contained within '"' characters, it  will
  2556.              be opened exactly as  specified,  and  (unless  it  contains  a
  2557.              directory path) will reference a file in the current directory.
  2558.     
  2559.                 If the filename is contained within the characters  '<'  and
  2560.              '>', it will be  prefixed  with  the  library  path  (See  'l='
  2561.              option), and will therefore reference a file  in  that  library
  2562.              directory. The default  library  directory  is  assumed  to  be
  2563.              '\mc'.
  2564.     
  2565.                 For example:
  2566.     
  2567.                         #include "header.h"     /* from current directory */
  2568.                         #include <stdio.h>      /* from library directory */
  2569.     MICRO-C                                                          Page: 53
  2570.  
  2571.  
  2572.        7.3 Error messages
  2573.     
  2574.              When MCP detects an error during processing of an include file,
  2575.           it displays an error message, which is preceeded by  the  filename
  2576.           and line number where the error occurs. If more than 10 errors are
  2577.           encountered, MCP will terminate.
  2578.     
  2579.              The following error messages are reported by MCP:
  2580.     
  2581.           7.3.1 Cannot open include file
  2582.     
  2583.                 A '#include' statement on the  indicated  line  specified  a
  2584.              file which could not be opened for reading.
  2585.     
  2586.           7.3.2 Invalid include file name
  2587.     
  2588.                 A '#include' statement on the  indicated  line  specified  a
  2589.              file  name  which  was  not  contained  within  '"'   or   '<>'
  2590.              characters.
  2591.     
  2592.           7.3.3 Invalid macro name
  2593.     
  2594.                 A '#define' statement on the indicated line contains a macro
  2595.              name which does not follow the name rules.
  2596.     
  2597.           7.3.4 Invalid macro parameter
  2598.     
  2599.                 A '#define' statement on the indicated line contains a macro
  2600.              parameter name which does not follow the name rules.
  2601.     
  2602.                 A reference to a macro does not have a proper ')'  character
  2603.              to terminate the parameter list.
  2604.     
  2605.           7.3.5 Too many errors
  2606.     
  2607.                 More  than  10  errors  has  been  encountered  and  MCP  is
  2608.              terminating.
  2609.     
  2610.           7.3.6 Too many macro definitions
  2611.     
  2612.                 MCP has encountered more '#define' statements  than  it  can
  2613.              handle.
  2614.     
  2615.           7.3.7 Too many macro parameters
  2616.     
  2617.                 A '#define' statement on the indicated line  specifies  more
  2618.              parameters to the macro than MCP can handle.
  2619.     
  2620.           7.3.8 Too many include files
  2621.     
  2622.                 MCP has encountered more nested '#include'  statements  than
  2623.              it can handle.
  2624.     MICRO-C                                                          Page: 54
  2625.  
  2626.  
  2627.           7.3.9 Undefined macro
  2628.     
  2629.                 A '#undef' or '#forget'  statement  on  the  indicated  line
  2630.              references a macro name which has not been defined.
  2631.     
  2632.           7.3.10 Unterminated comment
  2633.     
  2634.                 The END OF FILE has  been  encountered  while  processing  a
  2635.              comment.
  2636.     
  2637.           7.3.11 Unterminated string
  2638.     
  2639.                 A quoted string  on  the  indicated  line  has  no  end.  To
  2640.              continue a string to  the  next  line,  use  '\'  as  the  last
  2641.              character on the line. The '\' will  not  be  included  in  the
  2642.              string.
  2643.     MICRO-C                                                          Page: 55
  2644.  
  2645.  
  2646.     8. THE MICRO-C OPTIMIZER
  2647.     
  2648.           The MICRO-C optimizer is an output code filter which examines  the
  2649.        assembly code produced by the compiler, recognizing known patterns of
  2650.        inefficent code (using the "peephole" technique), and  replaces  them
  2651.        with more optimal code  which  performs  the  same  function.  It  is
  2652.        entirely table driven, allowing it to be modified for  virtually  any
  2653.        processor.
  2654.     
  2655.           Due its many table lookup operations, the  optimizer  may  perform
  2656.        quite slowly when processing a large  file.  For  this  reason,  most
  2657.        people prefer not to optimize during the debugging of a program,  and
  2658.        utilize the optimizer only when creating the final copy.
  2659.     
  2660.        8.1 The MCO command
  2661.     
  2662.              The format of the MICRO-C Optimizer command line is:
  2663.     
  2664.                     MCO [input_file] [output_file] [options]
  2665.     
  2666.              [input_file] is the name of the source file containing assembly
  2667.           statements to read. If no filenames are given, MCO will read  from
  2668.           standard input.
  2669.     
  2670.              [output_file] is the name of the file to  which  the  optimized
  2671.           assembly  code  is  written.  If  less  than  two  filenames   are
  2672.           specified, MCO will write to standard output.
  2673.     
  2674.           8.1.1 Command Line Options
  2675.     
  2676.                 MCO accepts the following command line [options]:
  2677.     
  2678.                 -d      - Instructs MCO to produce a 'debug' display on
  2679.                           standard output showing the  source code  which
  2680.                           it is removing and replacing in the input file.
  2681.                           NOTE: If you do not specify an  explict  output
  2682.                                 file, you will get the  debug  statements
  2683.                                 intermixed with  the  optimized  code  on
  2684.                                 standard output.
  2685.     
  2686.                 -q      - Instructs  MCO  to be quiet,  and not display
  2687.                           the startup message when it is executed.
  2688.     MICRO-C                                                          Page: 56
  2689.  
  2690.  
  2691.        8.2 Porting MCO to a new processor
  2692.     
  2693.              The MICRO-C Optimizer is completely table driven, and is fairly
  2694.           easy to port to new processors.
  2695.     
  2696.              The peephole optimization table  is  called  'peep_table',  and
  2697.           consists of two  sequential  character  string  entries  for  each
  2698.           optimization, and is terminated by single NULL pointer.
  2699.     
  2700.              The first is the "take" entry, and  represents  an  instruction
  2701.           sequence which (if found) is to be removed from the  output  file.
  2702.           The second  is  the  "give"  entry,  and  defines  a  sequence  of
  2703.           instructions to be placed in the output file at that  point.  NOTE
  2704.           that due to the way the optimizer removes and replaces instruction
  2705.           in the circular "peephole" buffer, the instructions in the  "give"
  2706.           entry ARE CODED IN REVERSE ORDER.
  2707.     
  2708.              Characters in the "take" entry with the high  bit  set  ('\200'
  2709.           and higher) are special characters which  represent  any  variable
  2710.           string which may occur in the instruction sequence,  and  will  be
  2711.           replaced with the same string wherever that  character  occurs  in
  2712.           the "give" entry. If  the  same  special  character  (eg:  '\200')
  2713.           occurs more than once  in  the  "take"  entry,  the  corresponding
  2714.           strings must be exactly the same or else the entire sequence  will
  2715.           not be matched.
  2716.     
  2717.              There may be up to 8 different  such  variable  strings  within
  2718.           each entry, the lower three bits  ('\201'-\'207')  indicate  which
  2719.           variable is referenced.
  2720.     
  2721.              The 4'th bit ('\21x') when used in a  "take"  entry,  allows  a
  2722.           match only if the variable string contains only the numeric digits
  2723.           ('0'-'9'). If any other character occurs, the instruction sequence
  2724.           will not be matched. This bit has no effect when used in a  "give"
  2725.           entry.
  2726.     
  2727.              The 5'th bit ('\22x') causes  the  variable  string  to  access
  2728.           through the "complement" table (see later). When used in a  "take"
  2729.           entry, this bit allows a match only if the variable string  occurs
  2730.           in  that  table.  When  used  in  a  "give"  entry,   causes   the
  2731.           complementary string to be output from the table.
  2732.     
  2733.              The processor will stop scanning  a  variable  string  when  it
  2734.           encounters the character which  immediately  follows  the  special
  2735.           character in the "take" entry, or at the end of the input line.
  2736.     MICRO-C                                                          Page: 57
  2737.  
  2738.  
  2739.              There are cases in which you may  not  want  the  optimizer  to
  2740.           further reduce code substitued for a particular  optimization.  In
  2741.           this case, simply include a single characer comment  in  the  GIVE
  2742.           entry, in such  a  position  as  to  prevent  the  optimizer  from
  2743.           recognizing that with any further TAKE entries.
  2744.     
  2745.              The optimzer also includes a "complement" table, which provides
  2746.           the ability to define and use "opposites" within an  optimization.
  2747.           The most common use for this  feature  is  in  the  processing  of
  2748.           conditional jumps, in cases  when  an  optimization  reverses  the
  2749.           logcal sense of a jump.
  2750.     
  2751.              The complement table is called  "not_table",  and  contains  an
  2752.           even number of character string entries. The table  is  terminated
  2753.           by a single NULL pointer. Each even/odd pair of  entries  in  this
  2754.           table are considered to be complementary strings.  When  a  "give"
  2755.           entry specifies that the complement of a variable string should be
  2756.           output, this table is scanned,  and  if  the  original  string  is
  2757.           found, the corresponding complementary entry is output instead. If
  2758.           the string is not found, it is output without modification.
  2759.     
  2760.              Note that you do not have to access the complementary table  in
  2761.           both the "give" and "take" optimization entries. For example,  you
  2762.           could specify a "special character" of '\221' in the "take" entry,
  2763.           indicating that you are using variable location 1,  and  that  the
  2764.           string must occur in the complement  table.  You  could  then  use
  2765.           "\201" in the "give" entry  to  output  the  original  string,  or
  2766.           "\221" to output the complement.
  2767.     MICRO-C                                                          Page: 58
  2768.  
  2769.  
  2770.     9. THE SOURCE LINKER
  2771.     
  2772.           Many small development environments have assemblers which  do  not
  2773.        directly support an object linker. This causes  a  problem  with  'C'
  2774.        development, because the library functions must be  included  in  the
  2775.        source code, with several drawbacks:
  2776.     
  2777.         1)  There is no way to automatically tell which library functions
  2778.             to include, therefore, you must do it manually.
  2779.     
  2780.         2)  'C' library functions must be  re-compiled every  time,  in
  2781.             order to avoid conflict between compiler generated labels.
  2782.     
  2783.           The MICRO-C Source Linker (SLINK) helps overcome  these  problems,
  2784.        by automatically  joining  previously  compiled  (assembly  language)
  2785.        source code from the library  to  your  programs.  Only  those  files
  2786.        containing functions which you  reference  are  joined  (Taking  into
  2787.        consideration functions called  by  the  included  library  functions
  2788.        etc...). As the files  are  joined,  compiler  generated  labels  are
  2789.        adjusted to be unique within each file.
  2790.     
  2791.        9.1 The SLINK Command
  2792.     
  2793.              The format of the SLINK command line is:
  2794.     
  2795.                    SLINK input_file... output_file [options]
  2796.     
  2797.              "input_file" is the name of  the  source  file  containing  the
  2798.           compiler output from your program.  Several  input  files  may  be
  2799.           specified, in which case they will all be processed into a  single
  2800.           output file.
  2801.     
  2802.              "output_file" is the name of  the  file  to  which  the  linked
  2803.           source code is written.
  2804.     MICRO-C                                                          Page: 59
  2805.  
  2806.  
  2807.           9.1.1 Command line options
  2808.     
  2809.                 SLINK accepts the following command line [options]:
  2810.     
  2811.                 ?       - Display command line help summary.
  2812.     
  2813.                 i=name  - Specify name of the External Index File.
  2814.     
  2815.                 -l      - Instructs SLINK to list each library used.
  2816.     
  2817.                 l=path  - Identifies the directory path which will be
  2818.                           taken to reference "library" files. If not
  2819.                           specified, it defaults to: '\mc\slib'
  2820.     
  2821.                 p=char  - Identifies the PREFIX character of compiler
  2822.                           generated symbols. Defaults is '?'.
  2823.     
  2824.                 -q      - Inhibit display of the startup message.
  2825.     
  2826.                 t=string- Prefix to prepend to temporary filenames.
  2827.                           If not specified, default is "$".
  2828.     
  2829.                 -w      - Sort WORD data to beginning of allocated bulk
  2830.                           unitialized storage (See $DD: directive).
  2831.     
  2832.        9.2 Multiple Input Files
  2833.     
  2834.              SLINK accepts multiple input files on  the  command  line,  and
  2835.           processes each file to build the output file. This allows  you  to
  2836.           "link" together several previously compiled (or assembly language)
  2837.           modules into one final program.
  2838.     
  2839.              Any external references  which  are  not  resolvable  from  the
  2840.           library are assumed to be resolved by  one  of  the  input  source
  2841.           files. Since SLINK does not have knowledge of the  public  symbols
  2842.           defined  in  the  input  files,  the  absence  of  an   externally
  2843.           referenced symbol will not be detected  until  the  assembly  step
  2844.           (where it will cause an undefined symbol error).
  2845.     MICRO-C                                                          Page: 60
  2846.  
  2847.  
  2848.        9.3 The External Index File
  2849.     
  2850.              SLINK uses a special file from the library to  determine  which
  2851.           symbols are in which files. This  files  is  called  the  EXTERNAL
  2852.           INDEX FILE, and is  found  in  the  library  directory  (see  'l='
  2853.           option), under the name "EXTINDEX.LIB".
  2854.     
  2855.              This  file  contains  entries  which  cross-reference  external
  2856.           symbols to files. Each entry is as follows:
  2857.     
  2858.             1)  Any lines beginning with '<' contain the names of files
  2859.                 which are to be processed and included at the BEGINNING
  2860.                 of the program (Before your source file). This the best
  2861.                 way to include the startup code and any runtime library
  2862.                 routines which are required  at  all  times,  and  also
  2863.                 provides a method of initializing any segments used.
  2864.                     eg: <6809rl.asm
  2865.     
  2866.             2)  Any lines beginning with '^' contain the names of files
  2867.                 which are to be processed AFTER the program and library
  2868.                 source files, but BEFORE any  uninitialized  data areas
  2869.                 are output. This is the best way to set up the location
  2870.                 and storage class of the uninitialized data  if it does
  2871.                 not immediately follow the executable program code, and
  2872.                 also providing any postamble needed by the segments.
  2873.     
  2874.             3)  Any lines beginning with '>' contain the names of files
  2875.                 which are to be processed at the END  of  the  program,
  2876.                 after all other information is output. This is the best
  2877.                 way to define heap memory storage,  and  to provide any
  2878.                 post-amble needed by the assembler.
  2879.     
  2880.             4)  Any lines beginning with '-' contain the names of files
  2881.                 which are to  be  included  if  any  of  the  following
  2882.                 symbols  (Up to another '<', '^', '>', '-' or '$')  are
  2883.                 referenced.
  2884.                     eg: -printf.asm format.asm fgets.asm fget.asm
  2885.     
  2886.                 NOTE: In most cases, the library functions will contain
  2887.                 indications of any external references that they do, in
  2888.                 which case SLINK will automatically include those files
  2889.                 even of the names are not mentioned on the '-' line. In
  2890.                 the example above, the following would suffice:
  2891.                         -printf.asm
  2892.     
  2893.             5)  The names  of  each  symbol  which  may  be  referenced
  2894.                 externally must follow the '<', '^', '>' or  '-' entry.
  2895.                 Symbols must occur one per line,  with  no  leading  or
  2896.                 trailing spaces.
  2897.                     eg: printf
  2898.                         fprintf
  2899.                         sprintf
  2900.     MICRO-C                                                          Page: 61
  2901.  
  2902.  
  2903.             6)  A line beginning with '$' is used to define the pseudo-
  2904.                 opcode used by SLINK to reserve uninitialized  data  at
  2905.                 the end of the output file.  Only  one  line  beginning
  2906.                 with '$' should be entered into the EXTINDEX.LIB  file.
  2907.                 The remainder of this line, including all  spaces  etc.
  2908.                 is entered between each symbol name,  and  the  decimal
  2909.                 size (in bytes) which is written to the output file.
  2910.                     eg: '$ RMB '    <- Quotes are for clarity
  2911.     
  2912.             A complete example:
  2913.     
  2914.                     -printf.asm
  2915.                     printf
  2916.                     fprintf
  2917.                     sprintf
  2918.                     -scanf.asm
  2919.                     scanf
  2920.                     fscanf
  2921.                     sscanf
  2922.                     <PREFIX.asm
  2923.                     ^MIDDLE.ASM
  2924.                     >SUFFIX.ASM
  2925.                     $ RMB
  2926.     
  2927.             In summary, the output file is written from:
  2928.     
  2929.                 1 - The '<' (prefix) files              *
  2930.                 2 - The program source files            *\
  2931.                 3 - Library files referenced (if any)   * > See note
  2932.                 4 - Segments 1-9 from above ...         */
  2933.                 5 - The '^' (middle) files
  2934.                 6 - Segments 1-9 from middle files      * See note
  2935.                 7 - Uninitialized data definitions      (if any)
  2936.                 8 - The '>' (suffix) files
  2937.                 9 - Segments 1-9 from sufix file(s)     * See note
  2938.     
  2939.             * NOTE: If these files contain multiple segments (see later),
  2940.                     all segments are grouped and written  in  seguential
  2941.                     order. IE: Seg 0 from all files is written, followed
  2942.                     by Seg 1, etc.
  2943.     MICRO-C                                                          Page: 62
  2944.  
  2945.  
  2946.        9.4 Source file information
  2947.     
  2948.           9.4.1 SLINK Directives
  2949.     
  2950.                 SLINK interpretes several "directives" which may be inserted
  2951.              in the  input  source  files  to  control  the  source  linking
  2952.              process. These directives must be on a separate line, beginning
  2953.              in column 1, and must be in  uppercase.  They  are  removed  by
  2954.              SLINK during processing, and thus will not cause conflict  with
  2955.              the normal syntax used by the assembler.
  2956.     
  2957.                                    $SE:<0-9>
  2958.     
  2959.                 The '$SE' directive is used  by  SLINK  to  define  multiple
  2960.              output segments. Up to 10 segments are allowed, with segment  0
  2961.              being the default which  is  selected  when  a  file  is  first
  2962.              encountered.  Other  segments  (1-9)  when  selected  via  this
  2963.              directive are written to temporary files, and re-joined at  the
  2964.              end of processing in  sequential  order.  this  allows  you  to
  2965.              separate sections of the source file (such as initialized data,
  2966.              literal pool etc.) into distinct areas of memory.
  2967.     
  2968.                               $DD:<symbol> <size>
  2969.     
  2970.                 The '$DD' directive is used  to  define  uninitialized  data
  2971.              storage areas, which will be allocated by SLINK between the '^'
  2972.              (middle) and '>' (suffix) files. This allows  you  to  allocate
  2973.              unitialized data outside of the bounds of the executable image,
  2974.              and thus exclude it from being saved to disk. This  action  may
  2975.              be thought  of  as  an  additional  (11'th)  segment  which  is
  2976.              available for uninitialized data only,  and  which  avoids  the
  2977.              temporary file read/write overhead associated with use  of  the
  2978.              other segments. This directive  is  normally  placed  into  the
  2979.              source file by the "def_global" routine  in  the  MICRO-C  code
  2980.              generator.
  2981.     
  2982.                                   $EX:<symbol>
  2983.     
  2984.                 The '$EX' directuve is used by SLINK to identify any symbols
  2985.              which are externally referenced. Whenever a '$EX' directive  is
  2986.              found, SLINK  searches  the  EXTINDX.LIB  file  for  the  named
  2987.              symbol, and marks the corresponding files for inclusion in  the
  2988.              program. This directive is normally placed into the source file
  2989.              by the "def_extern" routine in the MICRO-C code generator.
  2990.     
  2991.                 If you  are  writing  assembly  language  programs  for  the
  2992.              library, be sure to  include  "$SE:<0-9>"  directives  for  any
  2993.              segments you wish to access, "$DD:<symbol>  <size>"  directives
  2994.              for  any  uninitialized  data  you  wish   to   allocate,   and
  2995.              "$EX:<symbol>" directives for any symbols which you  externally
  2996.              reference. If you wish to place an assembly language comment on
  2997.              the same line, make sure it is separated from the remainder  of
  2998.              the directive by at least one space or tab character.
  2999.     MICRO-C                                                          Page: 63
  3000.  
  3001.  
  3002.                 Also, note that '<' (prefix) files may contain "$SE",  "$DD"
  3003.              and "$EX" directives, '^' (middle) files may contain "$SE"  and
  3004.              "$DD" but not "$EX", and '>' (suffix) files may  only  contains
  3005.              "$SE" directives. Basically, the rule is that "$EX"  cannot  be
  3006.              used after the libraries are included and "$DD" cannot be  used
  3007.              after the uninitialized data is output. Since  the  middle  and
  3008.              suffix files  are  ALWAYS  included,  simply  insure  that  all
  3009.              external references and data declarations needed by any of them
  3010.              are performed in the '<' (prefix) file.
  3011.     
  3012.           9.4.2 Compiler generated labels
  3013.     
  3014.                 As it processes each source file, SLINK scans each line  for
  3015.              symbols which consist of the '?' character (See  'p='  option),
  3016.              followed by a number. If it finds such as symbol, it inserts  a
  3017.              two character sequence ranging from 'AA' to  'ZZ'  between  the
  3018.              '?', and the number. This sequence will be incremented for each
  3019.              source file processed,  and  thus  insures  that  the  compiler
  3020.              generated symbols will be unique for each file.
  3021.     
  3022.                 If you  are  writing  assembly  language  programs  for  the
  3023.              library, you must be careful to  avoid  using  identical  local
  3024.              symbols in any of the library files, one way to do this  is  to
  3025.              use symbols which meet the above criteria.
  3026.     
  3027.        9.5 The SCONVERT command
  3028.     
  3029.              SCONVERT is a utility  which  assists  in  converting  existing
  3030.           assembly language  source  files  into  a  format  which  is  more
  3031.           suitable for use by the SLINK. Two main functions are performed:
  3032.     
  3033.           1) All comments are removed, and  all  spacing  is  reduced  to  a
  3034.              single space. This minimizes the size of the  file,  and  helps
  3035.              decrease linkage time.
  3036.     
  3037.           2) All symbols defined in the file which  are  not  identified  as
  3038.              "keep" symbols are converted to resemble the  MICRO-C  compiler
  3039.              generated symbols. This allows  SLINK  to  adjust  them  to  be
  3040.              unique within each source file.
  3041.     
  3042.              The format of the SCONVERT command line is:
  3043.     
  3044.     
  3045.                  SCONVERT [input_file] [output_file] [options]
  3046.     
  3047.              [input_file] is the name of  the  source  file  containing  the
  3048.           original assembly language program.  If  no  filenames  is  given,
  3049.           SCONVERT will read from standard input.
  3050.     
  3051.              [output_file] is the name of the file to  which  the  converted
  3052.           source code is written. If less  that  two  filenames  are  given,
  3053.           SCONVERT will write to standard output.
  3054.     MICRO-C                                                          Page: 64
  3055.  
  3056.  
  3057.           9.5.1 Command line options
  3058.     
  3059.                 SCONVERT accepts the following command line [options]:
  3060.     
  3061.                 ?       - Display command line help summary.
  3062.     
  3063.                 c=char  - Identifies the character used to begin a comment
  3064.                           at the trailing end of a source line. If no 'c='
  3065.                           is defined, SCONVERT will terminate processing at
  3066.                           the first blank or tab which follows the operand
  3067.                           field.
  3068.     
  3069.                 C=char  - Identifies the charcter which indicates a comment
  3070.                           line in the source code. Defaults to '*'.
  3071.     
  3072.                 k=name  - Identifies a symbol name to KEEP. This symbol will
  3073.                           not be converted. Multiple 'k=' are permitted.
  3074.     
  3075.                 K=file  - Identifies a file containing the names of symbols
  3076.                           to KEEP, one per line. Multiple 'K=' are permitted.
  3077.     
  3078.                 p=char  - Identifies the PREFIX character which is to be used
  3079.                           for the converted symbols. Defaults to '?'.
  3080.     
  3081.                 -q      - Instructs SCONVERT to be quiet, and not issue its
  3082.                           startup message.
  3083.     
  3084.                 SCONVERT identifies symbols in the input source file as  any
  3085.              string beginning with 'A-Z', 'a-z', '_' or '?', and  containing
  3086.              these charcters plus the digits '0-9'. If your assembler source
  3087.              files uses any other characters in its symbols, you  must  edit
  3088.              your sources and change the symbols.
  3089.     
  3090.        9.6 The SRENUM command
  3091.     
  3092.              SRENUM  is  a  small  utility  which  re-numbers  the  compiler
  3093.           generated symbols within a assembly language source file. This  is
  3094.           useful if you have made added symbols to the  file  by  hand,  and
  3095.           wish to make it "pretty" before adding it to the library etc.
  3096.     
  3097.              The format of the SRENUM command is:
  3098.     
  3099.                   SRENUM [input_file] [output_file] [options]
  3100.     
  3101.           9.6.1 Command line options
  3102.     
  3103.                 SRENUM accepts the following command line [options]:
  3104.     
  3105.                 ?       - Display command line help summary.
  3106.     
  3107.                 p=char  - Identifies the PREFIX character which is to be used
  3108.                           to recognize compiler generated symbols.
  3109.     
  3110.                 -q      - Instructs SRENUM to be quiet, and not issue its
  3111.                           startup message.
  3112.     MICRO-C                                                          Page: 65
  3113.  
  3114.  
  3115.        9.7 The SINDEX command
  3116.     
  3117.              SINDEX is a utility  which  assists  in  the  creation  of  the
  3118.           EXTINDEX.LIB file used by SLINK. When you run SINDEX, it  examines
  3119.           all of the '.ASM' files in the current  directory,  and  writes  a
  3120.           EXTINDEX.LIB file which contains a '-' type entry for  each  file,
  3121.           and  external  symbol  entries  for  any  labels  which  it  finds
  3122.           conforming to the 'C' naming conventions (Starts with 'a-z', 'A-Z'
  3123.           or '_', and contains only 'a-z', 'A-Z', '0-9' or '_').
  3124.     
  3125.              Once  you  have  run  SINDEX,  you  must  manually   edit   the
  3126.           EXTINDEX.LIB file, and remove any file or symbol entries which you
  3127.           do not wish to have available as external references, as  well  as
  3128.           insert any necessary entries for '<', '^', '>' and '$' commands.
  3129.     
  3130.           9.7.1 Command line options
  3131.     
  3132.                 SINDEX accepts the following command line options:
  3133.     
  3134.                 ?       - Display command line help summary.
  3135.     
  3136.                 i=name  - Specify name for index file to be written.
  3137.                           Dafault is "EXTINDEX.LIB".
  3138.     
  3139.                 You may also instruct SINDEX to search for  a  file  pattern
  3140.              other than '*.ASM' by passing it as a command line parameter.
  3141.     
  3142.                                  eg: SINDEX *.A
  3143.     
  3144.        9.8 The SLIB command
  3145.     
  3146.              Once you have constructed your source  library,  you  may  from
  3147.           time to time want to make minor changes to it, either  adding  new
  3148.           functions, or removing old ones ones.
  3149.     
  3150.              You could make such changes simply by editing the  EXTINDEX.LIB
  3151.           file, however you would have to be very  careful  not  to  add  or
  3152.           delete the wrong entry, and you would have to  manually  determine
  3153.           if adding or removing the file would adversly affect the remainder
  3154.           of the library. For example, you could accidently add a  duplicate
  3155.           of another symbol name, or remove a symbol which is referred to by
  3156.           another file.
  3157.     
  3158.              To simplify maintenance of source libraries, you can  make  use
  3159.           of the "Source Librarian", a utility program which  automates  the
  3160.           addition and removal of source files, and automatically reports of
  3161.           any inconsistancies occuring in the source library.
  3162.     
  3163.              To use SLIB, you must first position yourself to the  directory
  3164.           containing the source library. And then  execute  SLIB  using  the
  3165.           command options described later to indicate the action to be taken
  3166.           on the library. If you do  not  specify  any  actions,  SLIB  will
  3167.           simply examine the library and report its size and content.
  3168.     MICRO-C                                                          Page: 66
  3169.  
  3170.  
  3171.              You may use multiple command options in a single  SLIB  command
  3172.           if you wish to add and/or remove more than one file at a time.
  3173.     
  3174.              After  executing  any  command,  SLIB  will   report   on   any
  3175.           inconsistancies which it finds in the library. If any  are  found,
  3176.           and you have used a command which caused changes, SLIB will prompt
  3177.           for permission before writing the updated library file.
  3178.     
  3179.           9.8.1 Command line options
  3180.     
  3181.                 The following options control the action(s)  which  will  be
  3182.              performed by SLIB on the source library index file.
  3183.     
  3184.                 ?       - Display command line help summary.
  3185.     
  3186.                 ?=file  - Display information about named source file.
  3187.     
  3188.                 a=file  - Add specified file as standard functions.
  3189.     
  3190.                 i=index - Use the specified INDEX file, if not specified,
  3191.                           the filename 'EXTINDEX.LIB' is assumed.
  3192.     
  3193.                 m=file  - Add named source file as a MIDDLE file.
  3194.     
  3195.                 p=file  - Add named source file as a PREFIX file.
  3196.     
  3197.                 -q      - Quiet mode: SLIB will not display informational
  3198.                           messages or ask for permission to update index.
  3199.     
  3200.                 r=file  - Remove the named file from the index.
  3201.     
  3202.                 s=file  - Add named source file as a SUFFIX file.
  3203.     
  3204.                 -w      - Write inhibit:  SLIB will not write the updated
  3205.                           library index.  This is useful if you just want
  3206.                           to see what would happen if you add or remove a
  3207.                           file.
  3208.     MICRO-C                                                          Page: 67
  3209.  
  3210.  
  3211.        9.9 Making a source library
  3212.     
  3213.              To make a complete source linkable library, follow these  basic
  3214.           steps:
  3215.     
  3216.           1) If you have assembly language library functions, run the SINDEX
  3217.              utility to create an index file with the names of  any  symbols
  3218.              defined in them. Edit this file and remove all names which  are
  3219.              LOCAL to the files. Only the global function and variable names
  3220.              should remain. NOTE: Also leave in any other symbols  or  names
  3221.              which you don't want changed by SCONVERT.
  3222.     
  3223.           2) Use SCONVERT to convert  the  assembly  language  sources  into
  3224.              library format, using the index file created above as your KEEP
  3225.              file (K=EXTINDEX.LIB). You may send the output  files  directly
  3226.              to your source library directory.
  3227.     
  3228.           3) Edit the converted assembly  language  sources  to  change  any
  3229.              declarations for uninitialized data into '$DD' directives,  and
  3230.              to add any '$SE' and '$EX' directives which may be needed.
  3231.     
  3232.           4) Compile all of your 'C' library functions to assembly language,
  3233.              using a code generator which outputs the appropriate directives
  3234.              for SLINK. Send the ASM output files  to  your  source  library
  3235.              directory.
  3236.     
  3237.           5) From within your library  directory,  run  the  SINDEX  utility
  3238.              again. This will create  an  index  file  (EXTINDEX.LIB)  which
  3239.              contains the names of all global symbols.
  3240.     
  3241.           6) Edit the index file and remove any non-public symbol names. You
  3242.              should also change the headers for the '<', '^' and '>'  files,
  3243.              and add the '$' record for reserved memory information.
  3244.     
  3245.           7) Run the SLIB utility, to check the new  library  for  duplicate
  3246.              symbols,  unresolved  external   references   and   any   other
  3247.              inconsistancies.
  3248.     MICRO-C                                                          Page: 68
  3249.  
  3250.  
  3251.     10. THE MAKE UTILITY
  3252.     
  3253.           The MAKE utility provides a method of automating the  building  of
  3254.        larger programs consisting of more that one module. The main  benefit
  3255.        of MAKE is that it keeps track of  the  files  that  each  module  is
  3256.        dependant on, and will rebuild a module if any of  those  files  have
  3257.        been modified since  the  module  was  last  built.  This  frees  the
  3258.        programmer from  the  task  of  remembering  which  files  have  been
  3259.        changed, and the commands needed to rebuild the dependant modules.
  3260.     
  3261.        10.1 MAKEfiles
  3262.     
  3263.              To use MAKE, you must first create a MAKEFILE, which is a  text
  3264.           file containing entries for each module in the program. Each entry
  3265.           consists of a DEPENDANCY list, and a series of COMMANDS.
  3266.     
  3267.           10.1.1 MAKEfile Entries
  3268.     
  3269.                 A dependency list in MAKE is a line which contains the  name
  3270.              of the module, followed by a ':', followed by the names of  any
  3271.              files on which it depends. The module name MUST begin in column
  3272.              1.
  3273.     
  3274.                 When MAKE is invoked, it will process each dependancy  list,
  3275.              and  will  execute  any  following  commands  (up  to   another
  3276.              dependancy list) if (1) the module does not exist,  or  (2)  if
  3277.              any of the files to the right of the ':' have a timestamp which
  3278.              is later than that of the module. For example:
  3279.     
  3280.                 main.obj : main.c main.h \\mc\\stdio.h
  3281.                     \\mc\\mcc main.c main.asm
  3282.                     masm/ml main;
  3283.                     -del main.asm
  3284.     
  3285.                 In the above example, the 'main.obj' would  be  rebuilt  (by
  3286.              compiling and assembling 'main.c') if either it did not already
  3287.              exist, or any of 'main.c', 'main.h' or '\mc\stdio.h' was  found
  3288.              to have a later timestamp.
  3289.     
  3290.                 The '-' preceeding the 'del' command prevents it from  being
  3291.              displayed. Unless the '-q' option is enabled, MAKE will display
  3292.              any commands not preceeded by '-' as they are executed.
  3293.     
  3294.                 NOTE: To enter a single '\' in the MAKEFILE,  you  must  use
  3295.              '\\', this is because like 'C',  MAKE  uses  '\'  to  "protect"
  3296.              special  characters  which  otherwise  are  used  for   special
  3297.              functions (such as '\', '$' and '#'). The first '\'  "protects"
  3298.              the second one, allowing it to pass through as source text.
  3299.     MICRO-C                                                          Page: 69
  3300.  
  3301.  
  3302.           10.1.2 Macro Substitutions
  3303.     
  3304.                 Sometimes in a MAKEFILE, you have a single file or directory
  3305.              path that you use  over  and  over  again.  If  it  is  a  long
  3306.              directory path, this may  involve  a  lot  of  typing,  and  it
  3307.              becomes inconvenient to change that name (if you want to use  a
  3308.              different directory etc.) because it is repeated many times.
  3309.     
  3310.                 MAKE includes a MACRO facility, which allows you  to  define
  3311.              variable names which will be replaced with a text  string  when
  3312.              used in subsequent MAKEfile lines. Names are defined by placing
  3313.              them in the MAKEfile, followed by '=',  and  the  text  string.
  3314.              Macro names being defined MUST begin in  column  one,  and  may
  3315.              consist of the characters ('a'-'z', 'A'-'Z', '0'-'9', and '_').
  3316.     
  3317.                 Whenever MAKE encounters a '$' in the  file,  it  takes  the
  3318.              name immediately following, and performs the macro replacement:
  3319.     
  3320.                 mcdir = \\mc
  3321.                 main.obj : main.c main.h $mcdir\\stdio.h
  3322.                     $mcdir\\mcc main.c main.asm
  3323.                     masm/ml main;
  3324.                     del main.asm
  3325.     
  3326.     
  3327.                 When a macro name is immediately  followed  by  alphanumeric
  3328.              text, use a single '\' to  separate  it  from  the  text.  This
  3329.              "protects"  the  first  character  of  the  text   from   being
  3330.              interpreted as part of the macro name:
  3331.     
  3332.                 mcdir = \\mc\\
  3333.                 main.obj : main.c main.h $mcdir\stdio.h
  3334.                     $mcdir\mcc main.c main.asm
  3335.                     masm/ml main;
  3336.                     del main.asm
  3337.     
  3338.                 There  are  several  predefined  macro  symbols  which   are
  3339.              available:
  3340.     
  3341.     
  3342.                 $*      = The full name of the dependant module (name.type).
  3343.                 $@      = The name only of the dependant module.
  3344.                 $.      = The full name of each file in the dependancy list,
  3345.                           separated from each other by a single space.
  3346.                 $,      = The full name of each file in the dependancy list,
  3347.                           separated from each other by a single comma.
  3348.                 $:      = The name only of each file in the dependancy list,
  3349.                           separated from each other by a single space.
  3350.                 $;      = The name only of each file in the dependancy list,
  3351.                           separated from each other by a single comma.
  3352.     MICRO-C                                                          Page: 70
  3353.  
  3354.  
  3355.                 File names in the dependancy list which are preceeded by '-'
  3356.              will not be included in the '$. $, $: $;' macro expansions:
  3357.     
  3358.                 mcdir = \\mc
  3359.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  3360.                     $mcdir\\mcc $. $@.ASM
  3361.                     masm/ml $@;
  3362.                     del $@.ASM
  3363.     
  3364.           10.1.3 MAKEfile Comments
  3365.     
  3366.                 Whenever MAKE encounters the '#' character in the  MAKEFILE,
  3367.              it treats the remainder of the line as a comment, and does  not
  3368.              process it:
  3369.     
  3370.                 # Define Directories
  3371.                 mcdir = \\mc
  3372.     
  3373.                 # Build the MAIN module
  3374.                 main.obj : main.c -main.h -$mcdir\\stdio.h  # Dependants
  3375.                     $mcdir\\mcc $. $@.ASM                   # Compile
  3376.                     masm/ml $@;                             # Assemble
  3377.                     del $@.ASM                              # Delete tmp
  3378.     
  3379.           10.1.4 Ordering the MAKEfile
  3380.     
  3381.                 MAKE processes the MAKEfile is sequential fashion, with  the
  3382.              entries near the top being processed before  the  entries  near
  3383.              the bottom. To insure that each module is built  properly,  any
  3384.              files appearing in the dependancy list for a module  which  are
  3385.              themselves dependant  on  other  files,  should  have  MAKEfile
  3386.              entries which occur BEFORE the entries for  the  modules  which
  3387.              are dependant on them:
  3388.     
  3389.                 # Define Directories
  3390.                 mcdir = \\mc
  3391.                 # Build the MAIN module
  3392.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  3393.                     $mcdir\\mcc $. $@.ASM
  3394.                     masm/ml $@;
  3395.                     del $@.ASM
  3396.                 # Build the SUB module
  3397.                 sub.obj : sub.c -sub.h
  3398.                     $mcdir\\mcc $. $@.ASM
  3399.                     masm/ml $@;
  3400.                     del $@.ASM
  3401.                 # Bind the executable file
  3402.                 # NOTE: If either of the above modules is rebuilt,
  3403.                 #       this entry will be guarenteed to execute.
  3404.                 main.exe : main.obj sub.obj
  3405.                     LINK $:;
  3406.     MICRO-C                                                          Page: 71
  3407.  
  3408.  
  3409.        10.2 Directives
  3410.     
  3411.              Like 'C', MAKE recognizes several "directives" in the MAKEfile.
  3412.           These  directives  are  only  recognized  if  they  occur  at  the
  3413.           beginning of the input line:
  3414.     
  3415.           10.2.1 @include <filename>
  3416.     
  3417.                 This command causes the indicated file to be opened and read
  3418.              in as the source  text.  When  the  end  of  the  new  file  is
  3419.              encountered, processing will continue with the  line  following
  3420.              "@include" in the original MAKEfile.
  3421.     
  3422.           10.2.2 @ifdef <name> [name...]
  3423.     
  3424.                 Processes the following lines (up to @else of  @endif)  only
  3425.              if one of the given MACRO names is defined. NOTE: <name> should
  3426.              not be preceeded by '$', otherwise its CONTENTS will be tested.
  3427.     
  3428.           10.2.3 @ifndef <name> [name...]
  3429.     
  3430.                 Processes the following lines (up to @else of  @endif)  only
  3431.              if one of the given MACRO name is NOT defined.
  3432.     
  3433.           10.2.4 @ifeq <word1> <word2> [word3...]
  3434.     
  3435.                 Processes the following lines (up to @else of  @endif)  only
  3436.              if the first word matches one of the remaining  words  exactly.
  3437.              This is useful for testing the value of a defined MACRO symbol.
  3438.     
  3439.           10.2.5 @ifne <word1> <word2>
  3440.     
  3441.                 Processes the following lines (up to @else or  @endif)  only
  3442.              if the first word does not match any of the following words.
  3443.     
  3444.           10.2.6 @else
  3445.     
  3446.                 Processes the following lines (up to  @endif)  only  if  the
  3447.              preceeding @ifdef, @ifndef, @ifeq or @ifne was false.
  3448.     
  3449.           10.2.7 @endif
  3450.     
  3451.                 Terminates @ifdef, @ifndef, @ifeq and @ifne.
  3452.     
  3453.           10.2.8 @type <text>
  3454.     
  3455.                 Displays the following text.
  3456.     
  3457.           10.2.9 @abort [text]
  3458.     
  3459.                 Terminates MAKE with an 'Aborted!' message. Any text on  the
  3460.              remainder of the line will be appended to the message.
  3461.     MICRO-C                                                          Page: 72
  3462.  
  3463.  
  3464.        10.3 The MAKE command
  3465.     
  3466.              The format of the MAKE command line is:
  3467.     
  3468.                            MAKE [makefile] [options]
  3469.     
  3470.              [makefile] is the name of the MAKEfile to process. If  no  name
  3471.           is given, MAKE assumes the default name 'MAKEFILE'.
  3472.     
  3473.           10.3.1 Command Line Options
  3474.     
  3475.                 MAKE accepts the following command line [options]:
  3476.     
  3477.                 ?       - Causes MAKE to output a short summary  of  the
  3478.                           available command line options.
  3479.     
  3480.                 -d      - Instructs MAKE to operate in "debug" mode, and
  3481.                           display the commands which it  would  execute,
  3482.                           without actually executing them. This provides
  3483.                           a method of quickly testing the MAKEFILE.
  3484.     
  3485.                 -q      - Instructs MAKE to be quiet, and not display the
  3486.                           informational messages and commands executed as
  3487.                           it progresses.
  3488.     
  3489.         <name>=<text>   - Pre-defines a macro  of  the  specified  <name>
  3490.                           with the string value  <text>.  This  OVERRIDES
  3491.                           any definition within the MAKEfile,  which  may
  3492.                           be used to establish a "default" value.
  3493.     MICRO-C                                                          Page: 73
  3494.  
  3495.  
  3496.        10.4 The TOUCH command
  3497.     
  3498.              TOUCH is a small utility program which sets  the  timestamp  of
  3499.           one or more files to the current or  specified  time/date.  It  is
  3500.           useful as a  method  of  forcing  MAKE  to  recognize  a  file  as
  3501.           "changed", even when it has not.
  3502.     
  3503.              For example, if  you  had  decided  to  "undo"  several  recent
  3504.           changes by restoring a backup of 'main.c', the restored file  will
  3505.           probably have a timestamp which is  older  than  the  last  module
  3506.           which was built. In this case, MAKE would be unaware that the file
  3507.           has changed, and would therefore not rebuild the module.
  3508.     
  3509.              The TOUCH command could then be used to "update" the  timestamp
  3510.           of 'main.c' to the current time, causing MAKE to recognize it as a
  3511.           changed file.
  3512.     
  3513.                                   TOUCH main.c
  3514.     
  3515.              You could also use TOUCH to force rebuilding of several files:
  3516.     
  3517.                            TOUCH main.c sub1.c sub2.c
  3518.     
  3519.              Or even ALL '.C' files:
  3520.     
  3521.                                    TOUCH *.c
  3522.     
  3523.              TOUCH can also be used to set the timestamp of  a  file  to  an
  3524.           arbritrary value, this may be useful  to  PREVENT  a  change  from
  3525.           causing an update:
  3526.     
  3527.                          TOUCH main.c t=0:00 d=31/10/80
  3528.     
  3529.              NOTE: Use of the 't=' or 'd=' parameters to  TOUCH  allows  the
  3530.           possibility that a changed file  will  go  unnoticed.  CAUTION  is
  3531.           advised.
  3532.     
  3533.              The MSDOS  implementation  of  TOUCH  supports  '-h'  and  '-s'
  3534.           options, which cause it to set  the  timestamp  of  HIDDEN  and/or
  3535.           SYSTEM files. If these options are not used, TOUCH will not affect
  3536.           those types of files.
  3537.  
  3538.  
  3539.  
  3540.                                     MICRO-C
  3541.  
  3542.                                TABLE OF CONTENTS
  3543.  
  3544.  
  3545.                                                                          Page
  3546.  
  3547.      1. INTRODUCTION                                                        1
  3548.  
  3549.         1.1 Compiler Portability                                            2
  3550.         1.2 Code Portability                                                2
  3551.         1.3 The compiling process                                           3
  3552.  
  3553.      2. THE COMMAND CO-ORDINATOR                                            4
  3554.  
  3555.         2.1 The CC command                                                  4
  3556.         2.2 Using multiple object modules                                   6
  3557.  
  3558.      3. THE MICRO-C PROGRAMMING LANGUAGE                                    7
  3559.  
  3560.         3.1 Constants                                                       7
  3561.         3.2 Symbols                                                         7
  3562.         3.3 Arrays & Pointers                                              11
  3563.         3.4 Functions                                                      11
  3564.         3.5 Structures & Unions                                            12
  3565.         3.6 Control Statements                                             15
  3566.         3.7 Expression Operators                                           17
  3567.         3.8 Inline Assembly Language                                       19
  3568.         3.9 Preprocessor Commands                                          20
  3569.         3.10 Error Messages                                                21
  3570.         3.11 Quirks                                                        26
  3571.  
  3572.      4. ADVANCED TOPICS                                                    30
  3573.  
  3574.         4.1 Conversion Rules                                               30
  3575.         4.2 Assembly Language Interface                                    31
  3576.         4.3 Compiling for ROM                                              34
  3577.  
  3578.      5. THE MICRO-C COMPILER                                               35
  3579.  
  3580.         5.1 The MCC command                                                35
  3581.  
  3582.      6. PORTING THE COMPILER                                               36
  3583.  
  3584.         6.1 The "io" module                                                36
  3585.         6.2 The "code" module                                              38
  3586.         6.3 The "compile" module                                           44
  3587.         6.4 Porting without a linker                                       45
  3588.         6.5 Optimization Techniques                                        45
  3589.  
  3590.      7. THE MICRO-C PREPROCESSOR                                           48
  3591.  
  3592.         7.1 The MCP command                                                49
  3593.         7.2 Preprocesor Commands                                           50
  3594.  
  3595.     MICRO-C                                                Table of Contents
  3596.  
  3597.                                                                          Page
  3598.         7.3 Error messages                                                 53
  3599.  
  3600.      8. THE MICRO-C OPTIMIZER                                              55
  3601.  
  3602.         8.1 The MCO command                                                55
  3603.         8.2 Porting MCO to a new processor                                 56
  3604.  
  3605.      9. THE SOURCE LINKER                                                  58
  3606.  
  3607.         9.1 The SLINK Command                                              58
  3608.         9.2 Multiple Input Files                                           59
  3609.         9.3 The External Index File                                        60
  3610.         9.4 Source file information                                        62
  3611.         9.5 The SCONVERT command                                           63
  3612.         9.6 The SRENUM command                                             64
  3613.         9.7 The SINDEX command                                             65
  3614.         9.8 The SLIB command                                               65
  3615.         9.9 Making a source library                                        67
  3616.  
  3617.      10. THE MAKE UTILITY                                                  68
  3618.  
  3619.         10.1 MAKEfiles                                                     68
  3620.         10.2 Directives                                                    71
  3621.         10.3 The MAKE command                                              72
  3622.         10.4 The TOUCH command                                             73
  3623.